Hi Sergey,
I've run into an issue where I can insert (by code or by drag and drop) a webp image. It inserts OK, and saves OK. But once I save the rvf file and reopen it, any webp images show as a big "X" in my app (and throws an rve "Error loading file" error in other apps).
SVG, PNG, etc. still work as before. If I save a doc with a webp image in it as an RTF or DOCX the webp images save and reload OK. It's doing this in my app and in the actiontestuni demo. I tried an earlier version of my app using rve v22 and that works OK. I even made a simple test project with version 23 using open, save, and insert picture buttons and it works OK with PNGs, BMPs, SVGs and inserts webp OK, but doesn't reload an rvf file with webp images in it either. I get an rve error message in the test app that says "Error loading file."
So, wondering if something is amiss in rve version 23? Or, is there some new rve option I need to set for webp?
Thanks Sergey.
Stan
webp images not saving in rvf in version 23
-
- Site Admin
- Posts: 17632
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: webp images not saving in rvf in version 23
I do not understand how it could work in older versions, because image loading was not changed.
The image is saved to RVF correctly.
However, loading is the problem.
TRichView can use two ways to load images from RVF.
1. RVF contains a name of graphic class that was used to save it. TRichView tries to create this class using the system GetClass() function. This function can work only with classes registered using RegisterClass (or RegisterClasses) procedure. Unfortunately, TskGraphic is not registered and cannot be registered because this class is defined in the "implementation" section of the unit and cannot be accessed outside.
2. If the class cannot be created in this way, TRichView tries to detect graphic format and creates a class for this graphic format. TRichView can detect WebP images but cannot tell which class to use for it (and I cannot specify TskGraphic, because, as I said, it is not accessible).
As for RTF, they cannot contain WebP images, so the image is converted to another format on saving (depending on RTFOptions).
As for DocX, images must have the same problem as in RVF.
Fortunately, one more way of image loading is possible, using TPicture. In new versions of Delphi, TPicture can recognize some formats (including WebP) by content as well and use the correct graphic class for it. I modified the code to use it. Now, RVF and DocX containing WebP are loaded correctly.
I'll upload an update ASAP.
The image is saved to RVF correctly.
However, loading is the problem.
TRichView can use two ways to load images from RVF.
1. RVF contains a name of graphic class that was used to save it. TRichView tries to create this class using the system GetClass() function. This function can work only with classes registered using RegisterClass (or RegisterClasses) procedure. Unfortunately, TskGraphic is not registered and cannot be registered because this class is defined in the "implementation" section of the unit and cannot be accessed outside.
2. If the class cannot be created in this way, TRichView tries to detect graphic format and creates a class for this graphic format. TRichView can detect WebP images but cannot tell which class to use for it (and I cannot specify TskGraphic, because, as I said, it is not accessible).
As for RTF, they cannot contain WebP images, so the image is converted to another format on saving (depending on RTFOptions).
As for DocX, images must have the same problem as in RVF.
Fortunately, one more way of image loading is possible, using TPicture. In new versions of Delphi, TPicture can recognize some formats (including WebP) by content as well and use the correct graphic class for it. I modified the code to use it. Now, RVF and DocX containing WebP are loaded correctly.
I'll upload an update ASAP.
Re: webp images not saving in rvf in version 23
I might have been mistaken on older versions. At any rate, I came up with the following function yesterday that converts a webp to png and this seems to work:
Not sure if I need to handle wbmp. I'll probably remove that. I've never even seen a wbmp file.
I really don't like the webp format (and the trouble we're having with it is one reason why!), but I run into it enough that I wanted to handle it. I use this function when a webp is inserted or dropped. Once it's a png all is well.
Thanks for looking at it.
Stan
Code: Select all
function TForm1.ProcessWEBP(rv: TCustomRichViewEdit; FileName: string): boolean;
var
gr: TRVGraphic;
bmp: TBitMap;
begin
result := false;
try
if MatchStr(ExtractFileExt(FileName).ToLower,
['.wbmp','.webp']) then
begin
gr := RVGraphicHandler.LoadFromFile(FileName);
if gr <> nil then
if ExtractFileExt(FileName).ToLower = '.webp' then
begin
bmp := RVGraphicHandler.CreateBitmap(gr.Width, gr.Height,true,clBlack);
RVGraphicHandler.AssignToBitmap( gr, bmp, clBlack, true );
gr.Free; //free gr here so we don't get a leak
gr := RVGraphicHandler.GraphicToPng(bmp);
bmp.Free;
end;
if gr <> nil then
begin
gr.Transparent := true;
rv.InsertPicture( FileName, gr , rvvaBaseline );
result := true;
end;
end;
except
ShowMessage('Unable to process this file.');
end;
end;
I really don't like the webp format (and the trouble we're having with it is one reason why!), but I run into it enough that I wanted to handle it. I use this function when a webp is inserted or dropped. Once it's a png all is well.
Thanks for looking at it.
Stan
-
- Site Admin
- Posts: 17632
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: webp images not saving in rvf in version 23
Fixed in version 23.0.1
Re: webp images not saving in rvf in version 23
Works great, thanks Sergey.
Stan