Issue with Copying Images from RichView (RVF)

General TRichView support forum. Please post your questions here
Post Reply
tomr
Posts: 56
Joined: Wed Dec 09, 2020 9:36 am

Issue with Copying Images from RichView (RVF)

Post by tomr »

Hello RichView Support,
I’m encountering an issue with an image embedded in a RichEdit control using RichView.
I’ve attached an RVF file that demonstrates the problem.
Test Bild.rvf
Rvf-File with Picture
(39.13 KiB) Downloaded 6 times
When copying the image from this document, it cannot be pasted into applications like Paint. Additionally, the available paste options differ compared to images in other documents.
The image in question appears to be stored in Rich Text Format and RichView Format, whereas other images typically use Bitmap format.
This Picture:
Corrupted Picture Paste Special.png
Corrupted Picture Paste Special.png (8.21 KiB) Viewed 141 times
Other Pictures:
Picture Paste Special.png
Picture Paste Special.png (5.64 KiB) Viewed 141 times
This behavior can also be reproduced in the RichView demo application (“RichViewActions” test). Simply load the attached RVF file and try copying the image.

Do you have any insights into why this is happening or how it can be resolved?

Thank you in advance for your help.

Best regards,
Tom
standay
Posts: 336
Joined: Fri Jun 18, 2021 3:07 pm

Re: Issue with Copying Images from RichView (RVF)

Post by standay »

My guess is this may be by design. You can put something like this in your copy code or action. It's what I use:

Code: Select all

var
  gr: TGraphic;
  ATag: TRVTag;
  RVAlign: TRVVAlign;
  s: TRVUnicodeString;
  AData: THandle;
  APalette: HPALETTE;

begin

  if (rv.GetSelectedImage <> nil) then
  begin

      rv.GetCurrentPictureInfo( s, gr, RVAlign, ATag );
   
      if gr <> nil then
      begin
        //ShowMessage( 'x ' + gr.ClassName); //debug
        Clipboard.Open;
        gr.SaveToClipboardFormat(CF_PICTURE,AData,APalette);
        ClipBoard.SetAsHandle(CF_PICTURE,AData);
        Clipboard.Close;
      end
      else
      if not rv.CopyDef then
      begin
        ShowMessage('Unable to copy data.');
      end;
    end;

  end;
Stan (not with rv support)
tomr
Posts: 56
Joined: Wed Dec 09, 2020 9:36 am

Re: Issue with Copying Images from RichView (RVF)

Post by tomr »

Hi Stan,
Thanks for the help. It is working fine. :D
Sergey Tkachenko
Site Admin
Posts: 18106
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Issue with Copying Images from RichView (RVF)

Post by Sergey Tkachenko »

In the current version of the components, only TBitmap and TMetafile copying is implemented.
This is not a good solution, since some other graphic classes also support copying to the clipboard. For example, TJPEGImage (used in your document) and TWICImage copy as TBitmap, while TGIFImage copies in the "GIF Image" format (which is not a standard format).

The code provided by standay makes it possible to use the clipboard copy methods implemented in graphic classes, with the correction: all parameters of the SaveToClipboardFormat method are output parameters.
And the code can be simplified to:

Code: Select all

var
  gr: TGraphic;
begin
  gr := rv.GetSelectedImage;
  if (gr <> nil) then
    Clipboard.Assign(gr);
end;
CF_PICTURE is 'Delphi Picture' format. This is not a standard format, and as far as I can see in VCL/FMX source code, copying and pasting in this format is not implemented (at least, in runtime code). So it is useless.

Windows provides standard formats only for copying bitmaps and metafiles. However, a number of applications use non-standard formats, and I plan to add support for them in the next update.

For example, Chrome (and all browsers based on its engine) copy images in the "PNG" format. Some other applications (for example, Telegram) copy images using formats with MIME names, such as "image/png".
Post Reply