How to properly enlarge an image? lazarus / 39-Graphics ---------------------------------------------------------------------- michi_cc · 2011-10-08 14:13 Hello, I want to enlarge an image by a variable percentage. I first tried using TCanvas.StretchDraw, which was very fast, but the resulting image had very visible resizing artefacts. After that I tried to use TFPImageCanvas, which not only gave me an image equally bad, but executing it took like 5 minutes or so (not only the resizing, but the image loading was comparatively also very slow). Code extract below, with test.jpg being some random photo. Tested with 0.9.30.2RC1. Code: [Select]  Img := TFPMemoryImage.Create(0, 0);   Img.LoadFromFile('test.jpg');   W := Round(Img.Width * 1.5);   H := Round(Img.Height * 1.5);   Dest := TFPMemoryImage.Create(W, H);   with TFPImageCanvas.Create(Dest) do begin       StretchDraw(0, 0, W, H, Img);       Free;   end;   Dest.SaveToFile('out.jpg'); Is there something I've missed or done wrong, or do I simply have to use an external library to get good image resize? ---------------------------------------------------------------------- Shebuka · 2011-10-10 08:18 You need to use external lirary to have really good resample, look at http://wiki.lazarus.freepascal.org/BGRABitmap_tutorial_2#Stretch_the_i mage ---------------------------------------------------------------------- michi_cc · 2011-10-10 15:06 Well, if that's the way to go, that's the way to go. TBGRABitmap looks good, there is only one unfortunate problem: I want to pass the processed image data on to an external library which expects the image data to be delivered as RGBA instead of BGRA. Is the another comparable unit that can provide RGBA? If not, what's the best/fastest way to convert the data? ---------------------------------------------------------------------- Chronos · 2011-10-10 17:10 TBGRADefaultBitmap already have such method for swapping red and blue colors. Code: [Select]procedure TBGRADefaultBitmap.SwapRedBlue; var   n:    integer;   temp: longword;   p:    PLongword; begin   p := PLongword(Data);   n := NbPixels;   if n = 0 then     exit;   repeat     temp := p^;     p^   := ((temp and $FF) shl 16) or ((temp and $FF0000) shr 16) or       temp and $FF00FF00;     Inc(p);     Dec(n);   until n = 0;   InvalidateBitmap; end;