Page 1 of 2

Paste image from internet and resize

Posted: Tue Sep 02, 2014 10:41 am
by Testomatico
Hi,
is it possible to paste an image from the internet into the RichViewEdit? I'm using RichViewActions and Indy.
Afaik I need to do something like this:

Code: Select all

info:= TRVGraphicItemInfo.CreateEx(Sender.RVData, gr, rvvaMiddle);
info.ImageWidth:= 300;
info.ImageHeight:= 300;
if Sender.Style.Units=rvstuTwips then
  info.ConvertToDifferentUnits(rvstuTwips, nil, False);
info.UpdatePaletteInfo(Sender.DoInPaletteMode, False, Sender.RVPalette, Sender.PRVLogPalette);
s := Name;
 Result := TRVEditRVData(Sender.RVData).InsertSomething(info, s, SplitText,
          False, False, True);
My next idea was doing the download by myself on the Importer1ImageRequired2 event. But then i'm still not able to override the insert action.

Do you have any ideas?

Best regards
Testo

Posted: Tue Sep 02, 2014 10:59 am
by Testomatico
Oh, I meant
"is it possible to paste an image from the internet into the RichViewEdit and resize it at the same time"

Posted: Tue Sep 02, 2014 11:02 am
by Sergey Tkachenko
You use many undocumented methods in your code.
Please use InsertPicture and SetCurrentItemExtraIntProperty instead.

The example is here:
http://www.trichview.com/forums/viewtopic.php?t=5247
It assigns string properties to the downloaded pictures (title and alt) using SetCurrentItemExtraStrProperty. You can set integer properties (width and height similarly), using SetCurrentItemExtraIntProperty.

Posted: Tue Sep 02, 2014 12:58 pm
by Testomatico
OK, that works now pretty good.
But what if I want to paste html code including images from the clipboard?
Then I need to implement the RvHtmlImporter1ImageRequired2 event.
So, thats the actual problem. I can't insert images by myself in this event, beacuse it will do by itself. All I have to do is to override the "var Img: TGraphic" parameter, otherwise a default image will be added to the RichView content.

Posted: Tue Sep 02, 2014 4:22 pm
by Sergey Tkachenko
Yes, you need to process rvHtmlImport.OnImageRequired2, or RichView.OnImportPicture.

In these events, you need to create a graphic object and assign it to TGraphic parameter, and it will be inserted.

Yes, you cannot insert images in this event, you need to assign your image to the parameter.
Why do you want to do it in a different way?

Posted: Tue Sep 02, 2014 7:54 pm
by Testomatico
In these events, you need to create a graphic object and assign it to TGraphic parameter, and it will be inserted.
Thats the point. How can I set the size of the graphic here?
SetCurrentItemExtraStrProperty will obviously not work.

Posted: Wed Sep 03, 2014 4:51 am
by Sergey Tkachenko
You cannot, the importer uses <img width height> from HTML, if they are specified.
They are passed as parameters to OnImageRequired2, so if you want to resize the graphic instead, you can do it.

Posted: Wed Sep 03, 2014 1:37 pm
by Testomatico
So the following code should work, right?

Code: Select all

procedure TF_Main.RvHtmlImporter1ImageRequired2(Sender: TObject;
  const src: String; Width, Height: Integer; var Img: TGraphic);
begin
 Img := DownloadImage(src);
 Width:= 300;
 Height:= 300;
end;
But it does not :(

Posted: Wed Sep 03, 2014 5:37 pm
by Sergey Tkachenko
No, Width and Height are not var-parameters, so assignment to them is ignored.

Posted: Thu Sep 04, 2014 12:12 pm
by Testomatico
so if you want to resize the graphic instead, you can do it.
Ehm, ok. How can I now resize the graphic in the OnImageRequired2 event?
Assigning the parameteres will be ignored, manuel inserting isnt possible too. I don't see any other way to resize the image.

Posted: Thu Sep 04, 2014 12:24 pm
by Sergey Tkachenko
You have to modify source code of the importer to make them var parameters.
Sorry, I do not want to make this change, because it's not useful for 99% of users.

Posted: Thu Sep 04, 2014 1:04 pm
by Testomatico
Ok no problem :)
Thank you!

Similar Problem

Posted: Fri May 22, 2015 9:38 am
by Hillebrandt
Hello everyone,

I have a similar problem. In my software I have an error-report-system.
Next to simple TDBEdit-Fields for Version, Customer and some more
I use a TDBRichViewEdit for a description. The users insert screenshots
in this description. Also I make use of an "List & Label (c) combit"-Objekt,
for making a print. When I print such screenshots which are to wide,
the right part of the image wasn't printed.
My question is: Is there a possibility to run througt all image-objects
in the text to resize them to a maximum size? ... When I read about
the other questions from this board I'm nearly ashamed about asking
such simple question, but I don't find a solution myself. Maybe there is
already a very simple way.

Thanks for reading an a beautiful day.
Greetings from Germany
Hillebrand

Posted: Fri May 22, 2015 11:28 am
by Sergey Tkachenko
I assume you do not need to undo this operation.

You can do it in this way:

Code: Select all

const MAXPICTUREWIDTH=1000;

procedure TForm1.EnumItemsProc(RVData: TCustomRVData; ItemNo: Integer;  var UserData1: Integer;
  const UserData2: String; var ContinueEnum: Boolean); 
var Gr: TGraphic;
  VAlign: TRVVAlign;
  Tag: TRVTag;
  Name: TRVAnsiString;
begin 
  if (RVData.GetItemStyle(ItemNo)=rvsPicture) or 
    (RVData.GetItemStyle(ItemNo)=rvsHotPicture) then
  begin
    RVData.GetPictureInfo(ItemNo, Name, Gr, VAlign, Tag);
    if Gr.Width>MAXPICTUREWIDTH then begin
      RVData.SetItemExtraIntProperty(ItemNo, rvepImageWidth, MAXPICTUREWIDTH);
      RVData.SetItemExtraIntProperty(ItemNo, rvepImageHeight, Round(Gr.Height*MAXPICTUREWIDTH/Gr.Width));
      inc(UserData1);
    end;
  end;
  ContinueEnum := True; 
end; 


// how to use

var Changed: Integer; 

 Changed := 0;
MyRichView.RVData.EnumItems(EnumItemsProc, Changed, ''); 
if Changed<>0 then
  MyRichView.Format;

Looks good but change was lost

Posted: Tue May 26, 2015 10:56 am
by Hillebrandt
Hello Mr. Tkachenko,

If I run this It looks great, but the change was lost
when I do a "Post" on the DataSet.
Is there something I have to do so that the change is registred
by the TDBRichViewEdit? Something like "BeginEdit(); ... EndEdit();"
Maybe to abtract to understand, but you can look at this Delphi-Example:
www.hcbs.de/download/RichView.zip

Thanks for reading an a beautiful day.
Greetings from Germany
Hillebrand