Issue with Copying Images from RichView (RVF)
Issue with Copying Images from RichView (RVF)
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. 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: Other Pictures: 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
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. 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: Other Pictures: 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
Re: Issue with Copying Images from RichView (RVF)
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:
Stan (not with rv support)
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;Re: Issue with Copying Images from RichView (RVF)
Hi Stan,
Thanks for the help. It is working fine.
Thanks for the help. It is working fine.
-
Sergey Tkachenko
- Site Admin
- Posts: 18117
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Issue with Copying Images from RichView (RVF)
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:
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".
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;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".
Re: Issue with Copying Images from RichView (RVF)
Sergey, thanks for the simpler code. I found I had to do the following to handle svg images:
Is there a better way thsn this?
Stan
Code: Select all
if gr.ClassName.tolower <> 'tsksvggraphic' then
begin
Clipboard.Assign(gr);
end
else
if not rv.CopyDef then //handle possible svg
begin
ShowMessage('Unable to copy data.');
end;Stan
-
Sergey Tkachenko
- Site Admin
- Posts: 18117
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Issue with Copying Images from RichView (RVF)
You are right, TSkGraphic and TSkSvgGraphic must not be assigned to the Clipboard. And the only way to check for these classes is comparing class names.
These classes have an empty implementation of SaveToClipboardFormat method; and TClipboard does not expect it. As a result, uninitialized variables are used.
Please wait for the next update. I plan to upload it next week.
These classes have an empty implementation of SaveToClipboardFormat method; and TClipboard does not expect it. As a result, uninitialized variables are used.
Please wait for the next update. I plan to upload it next week.
Re: Issue with Copying Images from RichView (RVF)
Hi Sergey,
Thanks for the reply and information. Then I will wait for the next update.
Thanks for the reply and information. Then I will wait for the next update.
-
Sergey Tkachenko
- Site Admin
- Posts: 18117
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Issue with Copying Images from RichView (RVF)
Included in TRichView 24.1.3.
Re: Issue with Copying Images from RichView (RVF)
Hi Sergey,
The image copys are working but I'm getting a memory leak with SVG. I've used both CopyDef or CopyImage and get the same result. When running in my delphi 10.3 ide, I get a "cannot assign a TSkSvgGraphic to a TBitmap" error dialog:
And in madexcept, I get the following leak report when I close the app:
allocation number: 407215
program up time: 14.07 s
type: TBitmap
address: $ebe3550
size: 68
access rights: read/write
main thread ($46a8):
044a52b3 madExcept32.dll madExceptDbg 1736 GetMemCallback
00406fa8 SRDJournal.exe System 4799 @GetMem
00409056 SRDJournal.exe System 17394 TObject.NewInstance
00409837 SRDJournal.exe System 18773 @ClassCreate
0059ffdd SRDJournal.exe Vcl.Graphics 7951 TBitmap.Create
00409486 SRDJournal.exe System 17950 @IsClass
00772b71 SRDJournal.exe RVGrHandler 1088 TRVGraphicHandler.ToBitmap
00780896 SRDJournal.exe RVClipboard 734 RVSetBitmapToClipboard
009dbd2f SRDJournal.exe CRVFData 10909 TCustomRVFormattedData.CopyImage_
009dbfec SRDJournal.exe CRVFData 11074 TCustomRVFormattedData.CopyImage
009f5881 SRDJournal.exe RichView 3971 TCustomRichView.CopyImage
...
For now, I call clearleaks to suppress the madexcept error report when closing my app:
Stan
The image copys are working but I'm getting a memory leak with SVG. I've used both CopyDef or CopyImage and get the same result. When running in my delphi 10.3 ide, I get a "cannot assign a TSkSvgGraphic to a TBitmap" error dialog:
And in madexcept, I get the following leak report when I close the app:
allocation number: 407215
program up time: 14.07 s
type: TBitmap
address: $ebe3550
size: 68
access rights: read/write
main thread ($46a8):
044a52b3 madExcept32.dll madExceptDbg 1736 GetMemCallback
00406fa8 SRDJournal.exe System 4799 @GetMem
00409056 SRDJournal.exe System 17394 TObject.NewInstance
00409837 SRDJournal.exe System 18773 @ClassCreate
0059ffdd SRDJournal.exe Vcl.Graphics 7951 TBitmap.Create
00409486 SRDJournal.exe System 17950 @IsClass
00772b71 SRDJournal.exe RVGrHandler 1088 TRVGraphicHandler.ToBitmap
00780896 SRDJournal.exe RVClipboard 734 RVSetBitmapToClipboard
009dbd2f SRDJournal.exe CRVFData 10909 TCustomRVFormattedData.CopyImage_
009dbfec SRDJournal.exe CRVFData 11074 TCustomRVFormattedData.CopyImage
009f5881 SRDJournal.exe RichView 3971 TCustomRichView.CopyImage
...
For now, I call clearleaks to suppress the madexcept error report when closing my app:
Code: Select all
if (gr.ClassName.tolower = 'tsksvggraphic') then
begin
rv.CopyImage; //works for SVG, but creates a leak
madExcept.ClearLeaks(true,true); //suppress madexcept report
end;