Reload image?
-
whisper1980
- Posts: 118
- Joined: Sun May 25, 2025 6:41 pm
Reload image?
In FMX with TRichViewEdit on Android and iOS, my images are stored in a database and pulled during the OnImportPicture event (I use what I call linked images... only the URL identifying how to pull the image is saved in the TRichViewEdit's RTF). I allow a user to double click an image and edit it by adding arrows, circles, etc to focus a problem area in the photo. Is there a quick an easy way to refresh the image once I save it back to the database without having to reload the TRichViewEdit? I don't necessarily want to save everything prior to editing the image just to have to reload it to invoke the OnImportPicture event. I thought maybe there might be a better way.
-
Sergey Tkachenko
- Site Admin
- Posts: 18155
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Reload image?
You can find this image in the document and change it.
How is your image identified?
The code below assumes it's identified by item name, so GetItemText is used. It can also be identified by tag (GetItemTag) or property (GetItemExtraStrProperty(rvespImageFileName...)).
Searching for an image having the specified name:
Call:
If you use TRichViewEdit, you can reformat only the paragraph containing the found image. However, if the image is in table cell, this cell's editor must be activated:
How is your image identified?
The code below assumes it's identified by item name, so GetItemText is used. It can also be identified by tag (GetItemTag) or property (GetItemExtraStrProperty(rvespImageFileName...)).
Searching for an image having the specified name:
Code: Select all
function FindImage(RVData: TCustomRVData; const Name: String;
out ImgRVData: TCustomRVData; out ImgItemNo: Integer): Boolean;
var
i, r, c: Integer;
Table: TRVTableItemInfo;
begin
for i := 0 to RVData.ItemCount - 1 do
if (RVData.GetItem(i) is TRVGraphicItemInfo) and
(RVData.GetItemText(i) = Name) then
begin
ImgRVData := RVData;
ImgItemNo := i;
Result := True;
exit;
end
else if RVData.GetItem(i) is TRVTableItemInfo then
begin
Table := TRVTableItemInfo(RVData.GetItem(i));
for r := 0 to Table.RowCount - 1 do
for c := 0 to Table.ColCount - 1 do
if Table.Cells[r, c] <> nil then
begin
Result := FindImage(Table.Cells[r, c].GetRVData, Name, ImgRVData, ImgItemNo);
if Result then
exit;
end;
end;
Result := False;
end;Code: Select all
var
ImgRVData: TCustomRVData;
ImgItemNo: Integer;
begin
if FindImage(MyRichView.RVData, ImageName, ImgRVData, ImgItemNo) then
begin
ImgRVData.SetPictureInfo(ImgItemNo, ...);
MyRichView.Reformat;
end;
end;Code: Select all
var
ImgRVData: TCustomRVData;
ImgItemNo, ItemData: Integer;
RVE: TCustomRichViewEdit;
begin
if FindImage(MyRichViewEdit.RVData, ImageName, ImgRVData, ImgItemNo) then
begin
ImgRVData := ImgRVData.Edit;
RVE := ImgRVData.GetParentControl as TCustomRichViewEdit;
RVE.BeginItemModify(ImgItemNo, ImgRVData);
RVE.SetPictureInfo(ImgItemNo, ...);
RVE.EndItemModify(ImgItemNo, ImgRVData)
end;
end;