Page 1 of 1

Set Image Size When Using Action List's Insert Picture

Posted: Fri Oct 03, 2008 10:13 am
by fchintc
Hi,

I have a large JPG image at this location:

http://www.ctsoftware.com.my/refimages/large.jpg

When I use the rvaActions's Insert Picture menu to insert the image into a RichViewEdit, I would like to set the image size to about 100 x 100 and also allow the user to resize it.

Sergey, you gave me the following code but I don't know how to use it in the action list:-

Code: Select all

rve.TopLevelEditor.BeginUndoGroup(rvutInsert);
rve.TopLevelEditor.SetUndoGroupMode(True);
if rve.InsertPicture(...) then begin
  rve.SetCurrentItemExtraIntProperty(rvepImageHeight, 100, True);
  rve.SetCurrentItemExtraIntProperty(rvepImageWidth, 100, True);
  // The following line to be removed to allow user resize
  rve.SetCurrentItemExtraIntProperty(rvepResizable, 0, True);
end;
rve.TopLevelEditor.SetUndoGroupMode(False);
Thanks.

Frederick

Posted: Sat Oct 04, 2008 8:33 am
by fchintc
I am self-answering this post. What I did was to create a menu button in the action list menu and in the OnClick event of the menu item, I entered the following code (with examples from the help file and Sergey) :-

Code: Select all

var
   rve : TRichViewEdit;
   gr : TGraphic;
   pic : TPicture;
begin
   rve:=rchContent;  // This is the name of the control I am using
   if OpenPictureDialog1.Execute then begin
      pic := TPicture.Create;
      try
         pic.LoadFromFile(OpenPictureDialog1.FileName);
         gr := RV_CreateGraphics(TGraphicClass(pic.Graphic.ClassType));
         gr.Assign(pic.Graphic);
         rve.BeginUpdate;
         rve.TopLevelEditor.BeginUndoGroup(rvutInsert);
         rve.TopLevelEditor.SetUndoGroupMode(True);
         if rve.InsertPicture('', gr, rvvaBaseline) then begin
            rve.SetCurrentItemExtraIntProperty(rvepImageHeight, 200, True);
            rve.SetCurrentItemExtraIntProperty(rvepImageWidth, 200, True);
         end;
         rve.TopLevelEditor.SetUndoGroupMode(False);
         rve.EndUpdate;
      finally
         pic.Free;
      end;
   end;
end;
This set the inserted image to the size I wanted.

Frederick

Posted: Sat Oct 04, 2008 9:24 am
by Sergey Tkachenko
I plan to add a new property to this action - MaxImageSize.
If the image width or height exceeds this value, the image will be scaled down.

Posted: Mon Oct 06, 2008 12:24 am
by fchintc
That's great.

Looking forward to it.

Frederick