Home > Back-end >  [graphics problems consult] how to reduce the distortion of image zooming in
[graphics problems consult] how to reduce the distortion of image zooming in

Time:09-28

With Canvas StretchDraw can easily realize the image zooming, but sometimes the distortion is serious, is much less than the system's own drawing software, before also find an algorithm on the net, but I am a limited knowledge of the graphics, written code is a little unclear, the test failed,

Now to do an automatic batch thumbnail software for private use, hope to have a master glad, it is better for code!

CodePudding user response:

GDI functions can?

CodePudding user response:

Narrow generally is near several points on average, amplification of interpolation, the higher the accuracy, the slower speed

CodePudding user response:

Respond to similar problems before, image scaling is one of the best algorithm bicubic resample, GDI StretchBlt, StretchDIBits didn't use this algorithm, the need to achieve, but can use GDI + :

USES WinAPI GDIPAPI, WinAPI. GDIPOBJ;

Var
Bitmap1: TGPBitmap;
Bitmap2: TBitmap;
Graphic: TGPGraphics;
The begin
Bitmap1:=TGPBitmap. Create (' test. BMP);//BMP, GIF, jpeg, PNG...
Bitmap2:=TBitmap. Create;
With Bitmap2 do
The begin
Width:=Bitmap1 GetWidth * 2 div 3;//the shrink to 2/3 width
Height:=Bitmap1 GetHeight * 2 div 3;//the shrink to 2/3 height
PixelFormat:=pf32bit;
end;
Graphic:=TGPGraphics. Create (Bitmap2. Canvas. Handle).
Graphic. SetInterpolationMode (InterpolationModeHighQualityBicubic);//bicubic resample
Graphic. DrawImage (Bitmap1, 0, 0, Bitmap2 Width, Bitmap2, Height);
Bitmap2. SaveToFile (' test_resized. BMP);
Graphic. Free;
Bitmap2. Free;
Bitmap1. Free;
end;
  • Related