Tuesday, 15 November 2011
Home »
Tips and Trick Delphi
» How to Convert Graphic to File PNG
How to Convert Graphic to File PNG
To Share | Tuesday, 15 November 2011
Converting existing image on a TImage (can be a TBitmap, TJPEG) into PNG format and then save them into PNG files.
Declaration procedure:
TImageToPNG procedure (Src: TImage; const Dst: String);
var
PNG: TPNGObject;
BMP: TBitmap;
begin
PNG: = TPNGObject.Create;
try
/ / If the TImage a TBitmap, directly converted to PNG
if Src.Picture.Graphic is TBitmap then
PNG.Assign (TBitmap (Src.Picture.Graphic))
else
begin
/ / If the TImage is not a TBitmap, the first convert to a TBitmap, and then to PNG
BMP: = TBitmap.Create;
try
BMP.Assign (Src.Picture.Graphic);
PNG.Assign (BMP);
finally
BMP.Free;
end;
end;
/ / Save a File
PNG.SaveToFile (Dst);
finally
PNG.Free;
end
end;
Make sure TPNGImage already integrated with your Delphi
No comments:
Post a Comment