Put Image into clipboard lazarus / 13-General ---------------------------------------------------------------------- gilsonalencar · 2007-09-29 17:07 I have been trying to save a image (bitmap) to the clipboard on lazarus. I used SaveToClipboardFormat but i didn't had success. Please, help me. ---------------------------------------------------------------------- antonio · 2007-09-29 20:21 Clipboard.Assign(image.picture.bitmap); ---------------------------------------------------------------------- gilsonalencar · 2007-09-30 00:05 Thaks for your answer. ---------------------------------------------------------------------- tReby · 2009-01-23 05:45 Quote from: antonio on September 29, 2007, 10:21:08 pmClipboard.Assign(image.picture.bitmap); This doesn't work in lazarus 0.9.26 Please help me... ---------------------------------------------------------------------- Marc · 2009-01-23 10:02 This does work, but you didn't give us all details. Usually we cannot guess what might be wrong if you give a single line of code. IIRC your bugrep about this (and the answer I gave there) you load an jpeg image into a TImage. then the format of the image is TJPEGImage and not a TBitmap. When you "ask" a Image.Picure.Bitmap, it will convert to a TBitmap, loosing all data (this is the same for delphi). So either store a bitmap in TImage or use TImage.Picture.Graphic (which doesn't convert) ---------------------------------------------------------------------- tReby · 2009-01-26 01:24 so wats the possible code for this.. please give me a detail working example.. thanks ---------------------------------------------------------------------- Mike.Cornflake · 2010-10-24 08:32 The following code should work for you... As noted earlier, if you have a jpeg in the TImage then two things could be going wrong.  You might not be converting the jpeg to the a bitmap correctly.  The other thing is on Microsoft Windows itself (unsure about other os's) - I just spent 6 hours trying to get a jpeg on the clipboard.  Stepped through the Lazarus code and it all seems to work, but neither Word nor Paint recognise anything on the clipboard.  My working theory is that they don't recognise the 'image/jpg' mime type. The following code works for me on XP with various different image types in the TImage... Code: [Select]var   oBmp: TBitmap; begin     oBmp := TBitmap.Create;     try       oBmp.Assign(imgImage.Picture.Graphic);       Clipboard.Assign(oBmp);     finally       oBmp.Free;     end; end; ---------------------------------------------------------------------- Michael Diegelmann · 2015-06-27 11:25 When trying to migrate a graphics project from Delphi 7 to Lazarus I have encountered a problem with copying my graphic to the clipboard as a metafile. Here is my Delphi code: procedure TFormMain.MenuItemCopyGraphicOnClick(Sender:TObject); var ScreenDpi:Integer; Metafile:TMetafile; MetafileCanvas:TCanvas; begin  ScreenDpi:=Screen.PixelsPerInch;  Metafile:=TMetafile.Create;  with Metafile do  begin   Width:=GraphWidth; Height:=GraphHeight;    // pixel units   MMWidth:=GraphWidth*2540 div ScreenDpi;  // 0.01 mm units   MMHeight:=GraphHeight*2540 div ScreenDpi; // 0.01 mm units  end;  MetafileCanvas:=TMetafileCanvas.Create(Metafile,0);  DrawGraph(MetafileCanvas); // draws same graphic previously drawn to the Image component  MetafileCanvas.Free;  with Clipboard do begin Open; Assign(Metafile); Assign(Image.Picture.Bitmap); Close; end;  Metafile.Free; end; Copying the bitmap to the clipboard works fine but with Lazarus lacking the TMetafile and the TMetafileCanvas classes there seems to be no way to also copy the graphic as an (easily scalable) MetaGraphic to the clipboard. Any suggestion what I can do about this problem? (By the way, I have started using Lazarus just three days ago. So please do not expect me to be a pro!) ---------------------------------------------------------------------- wp · 2015-06-27 12:06 There is a simple meta file implementation in the TAChart package. It is not fully complete, but allows at least to copy the result of drawing actions to the clipboard. I checked with powerpoint that the meta file pasted is operational: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  TADrawerWMF; { TForm1 } procedure TForm1.PaintBox1Paint(Sender: TObject);begin  DrawIt(Paintbox1.Canvas, Paintbox1.BoundsRect);end; procedure TForm1.DrawIt(ACanvas: TCanvas; ARect: TRect);begin  ACanvas.Pen.Color := clRed;  ACanvas.Line(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom);  ACanvas.textOut(ARect.Left, (ARect.Top + ARect.Bottom) div 2, 'Hallo');end; procedure TForm1.BitBtn1Click(Sender:TObject);var  ScreenDpi:Integer;  Metafile:TMetafile;  MetafileCanvas:TCanvas;begin  ScreenDpi:=Screen.PixelsPerInch;  Metafile:=TMetafile.Create;  with Metafile do  begin    Width:=Paintbox1.Width;    Height:=Paintbox1.Height;    // pixel units    MMWidth:=Paintbox1.Width*2540 div ScreenDpi;  // 0.01 mm units    MMHeight:=Paintbox1.Height*2540 div ScreenDpi; // 0.01 mm units  end;  MetafileCanvas:=TMetafileCanvas.Create(Metafile,0);  DrawIt(MetafileCanvas, Rect(0, 0, Paintbox1.Width, Paintbox1.Height));  MetafileCanvas.Free;  Metafile.CopyToClipboard;  Metafile.Free;end; ---------------------------------------------------------------------- eny · 2015-06-27 23:36 Quote from: Michael Diegelmann on June 27, 2015, 01:25:45 pmBy the way, I have started using Lazarus just three days ago. So please do not expect me to be a pro! Try starting a new thread. Your answer does not help gilsonalencar (the TS). ---------------------------------------------------------------------- wp · 2015-06-28 09:27 QuoteYour answer does not help gilsonalencar (the TS).But Michael Diegelmann. I see nothing wrong when he highjacks a thread on images in clipboard for his question regarding metafiles. ---------------------------------------------------------------------- eny · 2015-06-28 16:03 Quote from: wp on June 28, 2015, 11:27:15 amBut Michael Diegelmann. I see nothing wrong when he highjacks a thread on images in clipboard for his question regarding metafiles. Neither did Michael Diegelmann that's why I'm helping you as well by suggesting to start a new thread.