[SOLVED] How do I get an image from clipboard? lazarus / 39-Graphics ---------------------------------------------------------------------- nsunny · 2010-12-23 03:36 I have looked around the forum but did not find a working code. Suppose, I have an image on the clipboard. I now want to retrieve the image from the clipboard on a TBitmap. And I want it to be drawn in a TBitmap (say... MyBitmap). I have tried the following: FOR COPYING (it worked): Code: [Select]  // MyBitmap is our TBitmap to be copied   Clipboard.Assign(MyBitmap); FOR PASTING (did not work): Code: [Select]if Clipboard.HasFormat(CF_Bitmap) then begin   MyBitmap.Assign(Clipboard); end; Little help from here: Basic Clipboard Operations (Cut/Copy/Paste) using the TClipboard object ---------------------------------------------------------------------- Leledumbo · 2010-12-23 05:06 What about LoadFromClipboardFormat? ---------------------------------------------------------------------- nsunny · 2010-12-23 06:14 I have tried: (A) Code: [Select]MyBitmap.LoadFromClipboardFormat( Clipboard.FindPictureFormatID ); (B) Code: [Select]MyBitmap.LoadFromClipboardFormat( Clipboard.FindFormatID('image/bmp') ); both raises error. ---------------------------------------------------------------------- Marc · 2010-12-23 09:12 What error ? ---------------------------------------------------------------------- nsunny · 2010-12-24 18:17 Quote from: Marc on December 23, 2010, 10:12:06 amWhat error ? Quoteboth raises error.  ooups! a little correction... (A) Code: [Select]MyBitmap.LoadFromClipboardFormat( Clipboard.FindPictureFormatID ); The above code raises an error: QuoteProject ZZZ raised exception class 'EInvalidGraphic' with message: TBitmap: Unsupported MimeType: But code (B) does not do anything. As if it was never written. ---------------------------------------------------------------------- longbow767 · 2011-01-04 14:06 Does this help: http://lists.lazarus.freepascal.org/pipermail/lazarus/2010- May/052693.html ---------------------------------------------------------------------- José Mejuto · 2011-01-04 18:50 Quote from: nsunny on December 24, 2010, 07:17:22 pmThe above code raises an error: Project ZZZ raised exception class 'EInvalidGraphic' with message: TBitmap: Unsupported MimeType: But code (B) does not do anything. As if it was never written.  Hello, In one of my programs I'm using: Code: [Select] ImageToEdit.Picture.LoadFromClipboardFormat(PredefinedC lipboardFormat(pcfDelphiBitmap)); It is working for me in Windows. ---------------------------------------------------------------------- nsunny · 2011-01-17 07:19 Quote from: JoshyFun on January 04, 2011, 07:50:21 pmIn one of my programs I'm using: Code: [Select] ImageToEdit.Picture.LoadFromClipboardFormat(PredefinedC lipboardFormat(pcfDelphiBitmap)); It is working for me in Windows. It worked for me too. Thanks. I want to do something more. I want this code only be executed if there is an image in the clipboard (not when text is in clipboard). I have tried the code below but failed: Code: [Select]    if Clipboard.HasFormat(PredefinedClipboardFormat(pcfDelphiBitmap)) then     begin         MyBitmap.LoadFromClipboardFormat(PredefinedClipboardFormat(pcf DelphiBitmap));     end; ---------------------------------------------------------------------- José Mejuto · 2011-01-17 19:12 Quote from: nsunny on January 17, 2011, 08:19:46 amI want to do something more. I want this code only be executed if there is an image in the clipboard (not when text is in clipboard). I have tried the code below but failed: Code: [Select]    if Clipboard.HasFormat(PredefinedClipboardFormat(pcfDelphiBitmap)) then     begin  MyBitmap.LoadFromClipboardFormat(PredefinedClipboardFormat(pcfDelphiB itmap));     end; Hello, I'm using: Code: [Select]  PictureAvailable:=false;   if Clipboard.HasFormat(PredefinedClipboardFormat(pcfDelphiBitmap)) then PictureAvailable:=true;   if Clipboard.HasFormat(PredefinedClipboardFormat(pcfBitmap)) then PictureAvailable:=true;   if PictureAvailable then begin ---------------------------------------------------------------------- nsunny · 2011-01-18 04:03 Quote from: JoshyFun on January 17, 2011, 08:12:59 pmHello, I'm using: Code: [Select]  PictureAvailable:=false;   if Clipboard.HasFormat(PredefinedClipboardFormat(pcfDelphiBitmap)) then PictureAvailable:=true;   if Clipboard.HasFormat(PredefinedClipboardFormat(pcfBitmap)) then PictureAvailable:=true;   if PictureAvailable then begin It worked!!! Thanks JoshyFun.