Delphi - bmp to png conversion fails
I have the following simple code to convert a clipboard image to bmp and then to png:
if Clipboard.HasFormat(CF_PICTURE) then
begin
bitmap := TBitmap.Create;
png := TPNGImage.Create;
try
bitmap.Assign(Clipboard);
bitmap.SaveToFile(ExtractFilePath(application.ExeName) + '\filename.bmp');
png.Draw(bitmap.Canvas, Rect(0, 0, bitmap.Width, bitmap.Height));
png.SaveToFile(extractfilepath(application.ExeName) + '\filename.png');
finally
bitmap.free;
png.free;
end;
end;
As long as the conversion to bmp is working and I can even open it in mspaint and see its contents, the conversion to png fails and I have an empty png image. What am I doing wrong?
+3
source to share