Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
[Solved] Lazarus Pascal - Better image scaling for TImage
Delphi, Lazarus, Free Pascal
(@hans)
Famed Member Admin
Joined: 13 years ago
Posts: 3060
Topic starter
January 9, 2026 6:44 AM
Specifically with Windows, I noticed how poorly a TImage scales.
With a little trick you can redraw the image using a different type of interpolation like so:
procedure BetterScaleImage(AWidth, AHeight: Integer; sourceImage:Timage);
var
srcImg, destImg: TLazIntfImage;
cnv: TLazCanvas;
interp: TFPBaseInterpolation;
begin
if sourceImage.Picture.Bitmap = nil then Exit;
srcImg := sourceImage.Picture.Bitmap.CreateIntfImage;
destImg := TLazIntfImage.CreateCompatible(srcImg, AWidth, AHeight);
try
cnv := TLazCanvas.Create(destImg);
try
interp := TFPBaseInterpolation.Create;
try
cnv.Interpolation := interp;
cnv.StretchDraw(0, 0, AWidth, AHeight, srcImg);
sourceImage.Picture.Bitmap.LoadFromIntfImage(destImg);
finally
interp.Free;
end;
finally
cnv.Free;
end;
finally
destImg.Free;
srcImg.Free;
end;
end;
After loading an image in your TImage, simply call BetterScaleImage(width,height,TImage) to scale it better.
Under Windows this will be a world of difference.
Enjoy!