• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5815
  • Last Modified:

delphi good quality resizing BITMAP

I am looking for a good BITMAP resizing library (I need to resize BITMAP picture and then have to save it).
I found some poor quality results, and I am looking for something like Photoshop result (good quality interpolation).
Any clues ?
0
yarek
Asked:
yarek
  • 2
  • 2
1 Solution
 
MerijnBSr. Software EngineerCommented:
GR32: http://www.graphics32.org/wiki/

great possibilities and quality
0
 
MerijnBSr. Software EngineerCommented:
I snippet I made a while ago, as an example how to use GR32.
In this case Lanczos algorithm is used (the line where StretchTransfer() is called).
But you case use other algorithms aswell: type TStretchFilter = (sfNearest, sfLinear, sfSpline, sfLanczos, sfMitchell);

asaik Spline is used often by PhotoShop


procedure TMainForm.ResizeImage(Image: TBitmap; OutImage: TJPEGImage);
const OUT_WIDTH = 480;
      OUT_HEIGHT = 360;
      BACK_COLOR = clWhite;
var SourceBMP: TBitmap32;
    DestBMP: TBitmap32;
    StretchFactor: real;
    StretchRect: TRect;
    Temp: TBitmap;
begin
 SourceBMP := TBitmap32.Create();
 SourceBMP.Assign(Image);

 DestBMP := TBitmap32.Create();
 DestBMP.SetSize(OUT_WIDTH, OUT_HEIGHT);
 DestBMP.Canvas.Brush.Color := BACK_COLOR;
 DestBMP.Canvas.FillRect(DestBMP.BoundsRect);
 DestBMP.StretchFilter := sfLanczos;

 StretchRect.Left := 0;
 StretchRect.Top := 0;
 StretchRect.Right := Image.Width;
 StretchRect.Bottom := Image.Height;

 if (Image.Width > OUT_WIDTH) or (Image.Height > OUT_HEIGHT) then
 begin
  if (Image.Width div 4) > (Image.Height div 3) then
  begin
   StretchFactor := Image.Width / OUT_WIDTH;

   StretchRect.Right := OUT_WIDTH;
   StretchRect.Bottom := round(Image.Height / StretchFactor);
  end
  else
  begin
   StretchFactor := Image.Height / OUT_HEIGHT;

   StretchRect.Bottom := OUT_HEIGHT;
   StretchRect.Right := round(Image.Width / StretchFactor);
  end;
 end;

 OffsetRect(StretchRect, (OUT_WIDTH - StretchRect.Right) div 2, (OUT_HEIGHT - StretchRect.Bottom) div 2);

 StretchTransfer(DestBMP, StretchRect, DestBMP.BoundsRect, SourceBMP, SourceBMP.BoundsRect, sfLanczos, dmOpaque);

 Temp := TBitmap.Create();
 Temp.Width := DestBMP.Width;
 Temp.Height := DestBMP.Height;

 DestBMP.DrawTo(Temp.Canvas.Handle, 0, 0);

 OutImage.Assign(Temp);

 Temp.Free();      
 SourceBMP.Free();
 DestBMP.Free();
end;
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now