2009/09/03 09:54

How to resize PNG file in Delphi ?


In case that you need to change PNG file size (width, height), you can use below function.

  procedure copy_to_resized_png( tar, src:string; w, h: Integer);
  var
    bmp: TBitmap;
    png, output: TPngImage;
  begin
    png := TPngImage.Create;
    png.LoadFromFile( src);

    bmp := TBitmap.Create;
    bmp.Width := w;
    bmp.Height := h;

    bmp.Canvas.StretchDraw( RECT( 0, 0, w, h), png);

    output := TPngImage.Create;
    output.Assign( bmp);
    output.SaveToFile( tar);

    output.Free;
    bmp.Free;
    png.Free;
  end;

In order to implement above function, I used TPngImage.
Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.