implementation
{$R *.lfm}
var
pngClipboardFormat : TClipboardFormat;
...
procedure TForm1.btnFromClipboardClick(Sender: TObject);
var
image : TBGRABitmap;
stream : TMemoryStream;
begin
try
try
//initialize
stream := TMemoryStream.Create;
if (Clipboard.HasFormat(PredefinedClipboardFormat(pcfBitmap))) AND (NOT(Clipboard.HasFormat(pngClipboardFormat))) then
begin
Clipboard.GetFormat(PredefinedClipboardFormat(pcfBitmap),stream);
stream.Position := 0;
image := TBGRABitmap.Create(stream);
scaleAndPreviewImage(image); // frees image
end;
if (Clipboard.HasFormat(pngClipboardFormat)) then
begin
Clipboard.GetFormat(pngClipboardFormat,stream);
stream.Position := 0;
image := TBGRABitmap.Create;
image.LoadFromStream(stream);
//if image.Empty then image.AlphaFill(255);
scaleAndPreviewImage(image); // frees image
end;
except
on E : Exception do ShowMessage(E.Message);
end;
finally
try
stream.Free;
except
on E : Exception do ShowMessage(E.Message);
end;
end;
end;
...
initialization
pngClipboardFormat := RegisterClipboardFormat({$IfDef WINDOWS}'PNG'{$Else}{$IfDef DARWIN}'public.png'{$Else}'image/png'{$EndIf}{$EndIf});