Search results for 'Resize PNG File'. 2 post(s) found.
- 2009/09/03 How to resize PNG file in Delphi ?
- 2009/09/03 How to resize and save PNG or Jpeg Image file ?
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;
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.
Another posts included in "Delphi"
| Delphi API to get the current working directory (0) | 2009/09/03 |
| Delphi API to get windows temporary directory (0) | 2009/09/03 |
| How to print external document ? (0) | 2009/09/09 |
| Get the length of arrays and a string (0) | 2009/08/22 |
| Delphi Pointer Types (0) | 2009/08/22 |
| How to read/wrtie INI file in Delphi ? (0) | 2009/08/21 |
| How to get file created time, modified time, and last accessed time ? (0) | 2009/08/19 |
| Delphi string conversion functions - AnsiToUTF-8, UTF8Encode, ... (0) | 2009/07/20 |
Trackback : Cannot send a trackbact to this post.
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();
}
{
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);
Another posts included in "C#"
| How to set an certain color as transparent color on bitmap (0) | 2009/09/03 |
| How to convert text string to integer ? (0) | 2009/09/04 |
| How to convert integer to text string ? (0) | 2009/09/04 |
| How to display message box in C# (0) | 2009/09/03 |
| How to convert bitmap image to jpeg image ? (0) | 2009/09/03 |
| To load image from file (0) | 2009/09/03 |
| Finding process name on OS (0) | 2008/09/22 |
| Convert System.DateTime to UNIX timestamp (0) | 2008/09/22 |

Prev

Rss Feed