Search results for 'Resize PNG File'. 2 post(s) found.

  1. 2009/09/03 How to resize PNG file in Delphi ?
  2. 2009/09/03 How to resize and save PNG or Jpeg Image file ?
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.

2009/09/03 09:51

How to resize and save PNG or Jpeg Image file ?


I tried to change image file with PictureBox control. Following is the example to convert image size.

private void copy_to_resized_png(string tar, string src, int w, int h)
{
  Image imgInput = Image.FromFile(src);
  Bitmap bitmapResized = new Bitmap( imgInput, w, h);

  // in case that you need to save as jpeg format
  // just change
  // ImageFormat.Png to ImageFormat.Jpeg
  bitmapResized.Save(tar, ImageFormat.Bmp);

  imgInput.Dispose();
  bitmapResized.Dispose();
}

You can call above function as following:
copy_to_resized_png( "c:\\tmp2_mask1.png", "c:\\widget_104_mask2_v2.png", w, h);


Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.