Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

How to copy pictures to clipboard

c001100
Posts: 2
Joined: Sun Feb 23, 2020 7:38 am

How to copy pictures to clipboard

Post by c001100 »

How to copy pictures to clipboard
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to copy pictures to clipboard

Post by salvadordf »

Hi,

Call TChromium.DownloadImage to download the image and implement the TChromium.OnDownloadImageFinished event to get the image data.

Then you only need to call TCefImageRef.GetAsBitmap to get the binary data and copy it to the clipboard.

The MiniBrowser demo uses TChromium.DownloadImage to download a sample image.
c001100
Posts: 2
Joined: Sun Feb 23, 2020 7:38 am

Re: How to copy pictures to clipboard

Post by c001100 »

I mean: copy the picture from the right-click menu
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to copy pictures to clipboard

Post by salvadordf »

You can add a custom context menu option called "Copy image to clipboard" that downloads the image and copies the image data to the clipboard.

See the MiniBrowser demo to know how to add a custom context menu option.
coater
Posts: 187
Joined: Sat Sep 29, 2018 1:51 pm

Re: How to copy pictures to clipboard

Post by coater »

salvadordf wrote: Wed May 06, 2020 9:03 am Hi,

Call TChromium.DownloadImage to download the image and implement the TChromium.OnDownloadImageFinished event to get the image data.

Then you only need to call TCefImageRef.GetAsBitmap to get the binary data and copy it to the clipboard.

The MiniBrowser demo uses TChromium.DownloadImage to download a sample image.
TempBinValue :=image.GetAsBitmap(1,CEF_COLOR_TYPE_RGBA_8888, CEF_ALPHA_TYPE_OPAQUE, TempWidth, TempHeight );
TempBinValue :=image.GetAsBitmap(1,aTempTCefColorType ,aTempTCefAlphaType, TempWidth, TempHeight );
all of these cannot work.
image.GetAsJpeg(1,0, TempWidth, TempHeight); the quality is very poor!

The sample didn't have code for TCefImageRef.GetAsBitmap and copy it to the clipboard,
May you write some example code, thank you very much!
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to copy pictures to clipboard

Post by salvadordf »

Use TChromiumCore.StartDownload with the image url and save it to a temporary directory.
That way you will have the original image without any quality loss due to compression.
coater
Posts: 187
Joined: Sat Sep 29, 2018 1:51 pm

Re: How to copy pictures to clipboard

Post by coater »

salvadordf wrote: Thu Nov 21, 2024 11:20 am Use TChromiumCore.StartDownload with the image url and save it to a temporary directory.
That way you will have the original image without any quality loss due to compression.
Is this the only way? It may be possible to downto a stream then copy to clipbord?
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to copy pictures to clipboard

Post by salvadordf »

There are several ways to get the images but this is the easiest method and it also gives the best image quality.
coater
Posts: 187
Joined: Sat Sep 29, 2018 1:51 pm

Re: How to copy pictures to clipboard

Post by coater »

Thank you very much!
coater
Posts: 187
Joined: Sat Sep 29, 2018 1:51 pm

Re: How to copy pictures to clipboard

Post by coater »

But how to download this?

img data="" src="data:image/jpg;base64
Post Reply