Paste image from internet and resize

General TRichView support forum. Please post your questions here
Testomatico
Posts: 15
Joined: Sat Mar 22, 2014 7:47 pm

Paste image from internet and resize

Post 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
Testomatico
Posts: 15
Joined: Sat Mar 22, 2014 7:47 pm

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

Post 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.
Testomatico
Posts: 15
Joined: Sat Mar 22, 2014 7:47 pm

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

Post 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?
Testomatico
Posts: 15
Joined: Sat Mar 22, 2014 7:47 pm

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

Post 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.
Testomatico
Posts: 15
Joined: Sat Mar 22, 2014 7:47 pm

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

Post by Sergey Tkachenko »

No, Width and Height are not var-parameters, so assignment to them is ignored.
Testomatico
Posts: 15
Joined: Sat Mar 22, 2014 7:47 pm

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

Post 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.
Testomatico
Posts: 15
Joined: Sat Mar 22, 2014 7:47 pm

Post by Testomatico »

Ok no problem :)
Thank you!
Hillebrandt
Posts: 14
Joined: Tue Feb 10, 2015 4:06 pm
Location: Papenburg, Germany

Similar Problem

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

Post 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;
Hillebrandt
Posts: 14
Joined: Tue Feb 10, 2015 4:06 pm
Location: Papenburg, Germany

Looks good but change was lost

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