Search image and change it

General TRichView support forum. Please post your questions here
Post Reply
Ragael
Posts: 3
Joined: Thu Jul 07, 2016 6:38 pm

Search image and change it

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Do you want to replace this image as an editing operation (that can be undone by the user)?
Ragael
Posts: 3
Joined: Thu Jul 07, 2016 6:38 pm

Post by Ragael »

No. The user will not change back the image
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Use SetPictureInfo method
Ragael
Posts: 3
Joined: Thu Jul 07, 2016 6:38 pm

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Post Reply