Issue with TDBRichViewEdit and Image Dimensions in Markdown Mode
Issue with TDBRichViewEdit and Image Dimensions in Markdown Mode
Hello everyone,
I am encountering an issue while working with TDBRichViewEdit in Markdown mode.
I am loading images from the filesystem instead of saving them directly in Markdown as base64.
The problem arises when I resize the images in the editor and then save the changes. Upon reloading the element, the image dimensions always revert to those of the original image and not the ones I previously modified.
I have attempted to implement the SaveImage2 event to capture the new image dimensions, but the Graphic variable seems to consistently return the height and width of the original image.
My question is: how can I obtain the dimensions of the modified image or save the new dimensions in Markdown?
Any help or guidance on resolving this issue would be greatly appreciated.
Thank you,
Alessandro Mancini
I am encountering an issue while working with TDBRichViewEdit in Markdown mode.
I am loading images from the filesystem instead of saving them directly in Markdown as base64.
The problem arises when I resize the images in the editor and then save the changes. Upon reloading the element, the image dimensions always revert to those of the original image and not the ones I previously modified.
I have attempted to implement the SaveImage2 event to capture the new image dimensions, but the Graphic variable seems to consistently return the height and width of the original image.
My question is: how can I obtain the dimensions of the modified image or save the new dimensions in Markdown?
Any help or guidance on resolving this issue would be greatly appreciated.
Thank you,
Alessandro Mancini
Re: Issue with TDBRichViewEdit and Image Dimensions in Markdown Mode
Sergey will know for sure but you may need to do something like this:
First, get the current image info into some vars:
Change your w and h, then set picture info with new values for height and width...
I ran into something like this and that's what I had to do to get the image(s) to resize. If you want to do this by item number, just use rv.GetPictureInfo and rv.SetPictureInfo instead. This might not fit your circumstnace exactly but maybe it will help.
Stan
First, get the current image info into some vars:
Code: Select all
rv.GetCurrentPictureInfo( s, gr, RVAlign, ATag );
w := gr.Width;
h := gr.Height;
Code: Select all
rv.SetCurrentPictureInfo( FFileName , gr, RVAlign, ATag );
rv.Reformat;
Stan
Re: Issue with TDBRichViewEdit and Image Dimensions in Markdown Mode
Thank you for your reply,
But GetCurrentPictureInfo returns the same information (original width and height) as the OnSaveImage2 event.
My question is: How can I retrieve the new width and height of an image that has been resized in the DbrichViewEdit?
But GetCurrentPictureInfo returns the same information (original width and height) as the OnSaveImage2 event.
Code: Select all
procedure TFormSintesi.EdtSintesiSaveImage2(Sender: TCustomRichView;
Graphic: TGraphic; SaveFormat: TRVSaveFormat; const Path,
ImagePrefix: TRVUnicodeString; var ImageSaveNo: Integer;
var Location: TRVUnicodeString; var DoDefault: Boolean);
var LNewFileName : String;
LOrigFilename: String;
LItem : TCustomRVItemInfo;
LGr : TGraphic;
LItemName : TRVUnicodeString;
LTag : TRVTag;
LRvAlign : TRVVAlign;
begin
if SaveFormat <> rvsfMarkdown then exit;
LItem := Sender.RVData.GetItem(RVStyle1.ItemNo);
LOrigFilename := Format('%s%s',[IDisplayEditable.IGriglia.GetCachePathImage,LItem.Hint]);
Location := Format('%s_%d.%s', [ImagePrefix,ImageSaveNo, GraphicExtension(TGraphicClass(Graphic.ClassType))]);
LNewFileName := Format('%s%s',[IDisplayEditable.IGriglia.GetCachePathImage,Location]);
inc(ImageSaveNo);
{$REGION 'Log'}
{TSI:IGNORE ON}
LogModule.ScriviLog('TFormSintesi.EdtSintesiSaveImage2',Format('Temporany filename %s Original filename %s',[LNewFileName,LOrigFilename]),tpliv4,True);
{TSI:IGNORE OFF}
{$ENDREGION}
EdtSintesi.GetCurrentPictureInfo( LItemName, LGr, LRvAlign, LTag );
{$REGION 'Log'}
{TSI:IGNORE ON}
LogModule.ScriviLog('TFormSintesi.EdtSintesiSaveImage2',Format('ItemName [%s] Size by event [%d/%d] Size by editor [%d/%d]',[LItemName,Graphic.Width,Graphic.Height,LGr.Width,LGr.Height]),tpliv4,True);
{TSI:IGNORE OFF}
{$ENDREGION}
Graphic.SaveToFile(LNewFileName);
if not IDisplayEditable.IGriglia.AddImageSummary(LNewFileName,LOrigFilename) then
begin
MessageBox(Handle, PChar(siLang_FormSintesi.GetTextOrDefault('IDS_S6' (* 'Errore in fase di salvataggio' *) )), PChar(STR_ERROR), MB_ICONERROR or MB_OK or MODALITY);
abort;
end;
Location := LNewFileName;
DoDefault := False;
end;
Re: Issue with TDBRichViewEdit and Image Dimensions in Markdown Mode
In my code, I set an extra integer property:
Then later I can get that property:
Then I can see the display width and actual width:
I'm using a regular rve and no database. But I found I had to save the info separately using the property. I'm not using markdown or a database so this may not apply to your need.
Stan
Code: Select all
rv.SetCurrentItemExtraIntProperty(rvepImageWidth, CurWidth , True);
Code: Select all
rv.GetItemExtraIntProperty(ItemNo, rvepImageWidth, i );
Code: Select all
msg := msg + #13'Display/Actual Width: ' + i.ToString + '/' + gr.Width.ToString;
Stan
Re: Issue with TDBRichViewEdit and Image Dimensions in Markdown Mode
when you apply rv.SetCurrentItemExtraIntProperty(rvepImageWidth, CurWidth , True); ?
and whats its CurWidth ?
thank you for yout support
and whats its CurWidth ?
thank you for yout support
-
- Site Admin
- Posts: 17565
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Issue with TDBRichViewEdit and Image Dimensions in Markdown Mode
Markdown does not have keywords for specifying image size, so yes, images will be reverted to the original size after reloading.
Yes, you can modify images on saving in OnSaveImage2.
This event has "hidden" parameters (Sender.Style.RVData and Sender.Style.ItemNo) that you can use to get the image size.
PS: as for *Current* methods, they work with the object at the caret position.
Yes, you can modify images on saving in OnSaveImage2.
This event has "hidden" parameters (Sender.Style.RVData and Sender.Style.ItemNo) that you can use to get the image size.
Code: Select all
var
ImageWidth, ImageHeight: Integer;
LRVData: TCustomRVData;
begin
LRVData := TCustomRVData(Sender.Style.RVData);
LRVData.GetItemExtraIntProperty(Sender.Style.ItemNo, rvepImageWidth, ImageWidth);
LRVData.GetItemExtraIntProperty(Sender.Style.ItemNo, rvepImageHeight, ImageHeight);
ImageWidth := Sender.Style.GetAsStandardPixels(ImageWidth);
ImageHeight := Sender.Style.GetAsStandardPixels(ImageHeight);
{
Here you can use ImageWidth and ImageHeight. For unresized image, they are zero.
}
end;
Re: Issue with TDBRichViewEdit and Image Dimensions in Markdown Mode
Thank you very much for the reply! I really appreciate your help.
I also wanted to compliment you on the excellent library you have produced.
In my opinion, it is a must-have for Delphi.
Thank you again.
I'll try the tests tomorrow.
I also wanted to compliment you on the excellent library you have produced.
In my opinion, it is a must-have for Delphi.
Thank you again.
I'll try the tests tomorrow.
Re: Issue with TDBRichViewEdit and Image Dimensions in Markdown Mode
Okay, it works perfectly
One other question about OnSaveImage2: Can it retrieve the name of the image? For example, if I have this ![image](<IMAGE_NAME.jpg>) can I retrieve 'IMAGE_NAME.jpg
One other question about OnSaveImage2: Can it retrieve the name of the image? For example, if I have this ![image](<IMAGE_NAME.jpg>) can I retrieve 'IMAGE_NAME.jpg
-
- Site Admin
- Posts: 17565
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Issue with TDBRichViewEdit and Image Dimensions in Markdown Mode
If rvoAssignImageFileNames is not included in RichView.Options, then this file name is lost on loading.
If rvoAssignImageFileNames is included in RichView.Options, then this file name is stored in rvespImageFileName property.
In OnSaveImage2, you can get it as
If rvoAssignImageFileNames is included in RichView.Options, then this file name is stored in rvespImageFileName property.
In OnSaveImage2, you can get it as
Code: Select all
var
ImageFileName: String;
RVData.GetItemExtraStrProperty(Sender.Style.ItemNo, rvespImageFileName, ImageFileName);