Page 1 of 1
Search image and change it
Posted: Thu Jul 07, 2016 6:47 pm
by Ragael
Hi, I'd like know how search for a image (by name) and replace with another image. In runtime!
Nowadays I am finding the image using GetItem(x), but I am having difficulties with replace the image.
Posted: Thu Jul 07, 2016 7:19 pm
by Sergey Tkachenko
Do you want to replace this image as an editing operation (that can be undone by the user)?
Posted: Thu Jul 07, 2016 7:36 pm
by Ragael
No. The user will not change back the image
Posted: Thu Jul 07, 2016 8:51 pm
by Sergey Tkachenko
Use SetPictureInfo method
Posted: Fri Jul 08, 2016 11:01 am
by Ragael
I am using the code:
Code: Select all
SRichViewEdit1.StartEditing(srvrveHeader);
for x := 0 to SRichViewEdit1.ActiveEditor.ItemCount-1 do
begin
if SRichViewEdit1.ActiveEditor.GetItemStyle(x) = rvsPicture then
begin
SRichViewEdit1.ActiveEditor.GetPictureInfo(x,AName,Agr,AVAlign,ATag);
if ListBoxCamposImagem.Items.IndexOf(AName) > -1 then
begin
bmp := TBitmap.Create;
bmp.LoadFromFile('img.bmp');
SRichViewEdit1.ActiveEditor.SetPictureInfo(x,AName,bmp,AVAlign,ATag);
SRichViewEdit1.Format;
bmp.free;
end;
end;
end;
It does not show error, but does not change the image also.
Can you help me fix it? And I'd like to maintain the width and height of the previous image.
Posted: Fri Jul 08, 2016 11:41 am
by Sergey Tkachenko
Does not free bmp, after calling SetPictureInfo it's owned by the editor.
Call Format one time at the end, instead of after each replacement.
Note: this code processes only the main document, it does not change pictures in table cells, footnotes, endnotes and text boxes.
If you need, I can explain how to do it.