delphi good quality resizing BITMAP

Posted on 2007-08-08
Last Modified: 2012-06-27
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 ?
Question by:yarek
    LVL 19

    Accepted Solution


    great possibilities and quality
    LVL 10

    Expert Comment

    LVL 10

    Expert Comment

    LVL 19

    Expert Comment

    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;
     SourceBMP := TBitmap32.Create();

     DestBMP := TBitmap32.Create();
     DestBMP.Canvas.Brush.Color := BACK_COLOR;
     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
      if (Image.Width div 4) > (Image.Height div 3) then
       StretchFactor := Image.Width / OUT_WIDTH;

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

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

     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);



    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
    Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now