Set Image Size When Using Action List's Insert Picture

General TRichView support forum. Please post your questions here
Post Reply
fchintc
Posts: 47
Joined: Thu Oct 25, 2007 2:49 pm

Set Image Size When Using Action List's Insert Picture

Post 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
fchintc
Posts: 47
Joined: Thu Oct 25, 2007 2:49 pm

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

Post 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.
fchintc
Posts: 47
Joined: Thu Oct 25, 2007 2:49 pm

Post by fchintc »

That's great.

Looking forward to it.

Frederick
Post Reply