Recent

Author Topic: Put Image into clipboard  (Read 14868 times)

gilsonalencar

  • New Member
  • *
  • Posts: 48
Put Image into clipboard
« on: September 29, 2007, 07:07:16 pm »
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

  • Hero Member
  • *****
  • Posts: 605
RE: Put Image into clipboard
« Reply #1 on: September 29, 2007, 10:21:08 pm »
Clipboard.Assign(image.picture.bitmap);

gilsonalencar

  • New Member
  • *
  • Posts: 48
Put Image into clipboard
« Reply #2 on: September 30, 2007, 02:05:31 am »
Thaks for your answer.

tReby

  • Newbie
  • Posts: 4
Re: RE: Put Image into clipboard
« Reply #3 on: January 23, 2009, 06:45:33 am »
Clipboard.Assign(image.picture.bitmap);

This doesn't work in lazarus 0.9.26

Please help me...

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2674
Re: Put Image into clipboard
« Reply #4 on: January 23, 2009, 11:02:51 am »
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)
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

tReby

  • Newbie
  • Posts: 4
Re: Put Image into clipboard
« Reply #5 on: January 26, 2009, 02:24:24 am »
so wats the possible code for this.. please give me a detail working example.. thanks

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1269
Re: Put Image into clipboard
« Reply #6 on: October 24, 2010, 10:32:53 am »
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;
Lazarus Trunk/FPC latest fixes on Windows 11
  I'm getting old and stale.  Slowly getting used to git, I'll get there...

Michael Diegelmann

  • New member
  • *
  • Posts: 7
    • MichaelGraphics Software Tools
Re: Put Image into clipboard
« Reply #7 on: June 27, 2015, 01:25:45 pm »
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!)
« Last Edit: June 27, 2015, 01:28:34 pm by Michael Diegelmann »

wp

  • Hero Member
  • *****
  • Posts: 13418
Re: Put Image into clipboard
« Reply #8 on: June 27, 2015, 02:06:52 pm »
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][+][-]
  1. uses
  2.   TADrawerWMF;
  3.  
  4. { TForm1 }
  5.  
  6. procedure TForm1.PaintBox1Paint(Sender: TObject);
  7. begin
  8.   DrawIt(Paintbox1.Canvas, Paintbox1.BoundsRect);
  9. end;
  10.  
  11. procedure TForm1.DrawIt(ACanvas: TCanvas; ARect: TRect);
  12. begin
  13.   ACanvas.Pen.Color := clRed;
  14.   ACanvas.Line(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom);
  15.   ACanvas.textOut(ARect.Left, (ARect.Top + ARect.Bottom) div 2, 'Hallo');
  16. end;
  17.  
  18. procedure TForm1.BitBtn1Click(Sender:TObject);
  19. var
  20.   ScreenDpi:Integer;
  21.   Metafile:TMetafile;
  22.   MetafileCanvas:TCanvas;
  23. begin
  24.   ScreenDpi:=Screen.PixelsPerInch;
  25.   Metafile:=TMetafile.Create;
  26.   with Metafile do
  27.   begin
  28.     Width:=Paintbox1.Width;
  29.     Height:=Paintbox1.Height;    // pixel units
  30.     MMWidth:=Paintbox1.Width*2540 div ScreenDpi;  // 0.01 mm units
  31.     MMHeight:=Paintbox1.Height*2540 div ScreenDpi; // 0.01 mm units
  32.   end;
  33.   MetafileCanvas:=TMetafileCanvas.Create(Metafile,0);
  34.   DrawIt(MetafileCanvas, Rect(0, 0, Paintbox1.Width, Paintbox1.Height));
  35.   MetafileCanvas.Free;
  36.   Metafile.CopyToClipboard;
  37.   Metafile.Free;
  38. end;
  39.  
« Last Edit: June 27, 2015, 02:09:10 pm by wp »

eny

  • Hero Member
  • *****
  • Posts: 1658
Re: Put Image into clipboard
« Reply #9 on: June 28, 2015, 01:36:43 am »
By 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).
All posts based on: Win11; Lazarus 4_4  (x64) 12-02-2026 (unless specified otherwise...)

wp

  • Hero Member
  • *****
  • Posts: 13418
Re: Put Image into clipboard
« Reply #10 on: June 28, 2015, 11:27:15 am »
Quote
Your 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

  • Hero Member
  • *****
  • Posts: 1658
Re: Put Image into clipboard
« Reply #11 on: June 28, 2015, 06:03:28 pm »
But 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.
All posts based on: Win11; Lazarus 4_4  (x64) 12-02-2026 (unless specified otherwise...)

 

TinyPortal © 2005-2018