Reputation: 1351
I have the following simple code to convert 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;
While the conversion to bmp works and I can even open it in mspaint and see its content, the conversion to png fails and I have a blank png image. What am I doing wrong?
Upvotes: 3
Views: 4358
Reputation: 613491
You have not set the dimensions (height and width) of the PNG image object. You would need to do that before drawing to it.
Easier however would be a simple assignment:
png.Assign(Bitmap);
Upvotes: 12