Save RVF file with resized image

General TRichView support forum. Please post your questions here
Post Reply
standay
Posts: 272
Joined: Fri Jun 18, 2021 3:07 pm

Save RVF file with resized image

Post by standay »

Hi Sergey,

If this has been answered before let me know.

I often import a large image and resize it in a regular rve. No problem there. What I wanted to know is, after resizing the image how do I then save the rvf file with the resized image?

I've been able to resize them in the editor or upon import, but when I save the file the image is saved in its original (not displayed) size. I want to save the file with the image at the size it's being displayed in the doc.

I can resize them outside of my rve and then paste them in, but if there's a way to save the rve file without that extra step that would be great.

Thanks Sergey

Stan
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Save RVF file with resized image

Post by Sergey Tkachenko »

Can you send me a simple project reproducing this problem?
Of course, sizes of resized images must be stored in RVF.
standay
Posts: 272
Joined: Fri Jun 18, 2021 3:07 pm

Re: Save RVF file with resized image

Post by standay »

Hi Sergey,

I don't have any code yet that I'm trying to use to do this with other than this kind of thing (or using the mouse):

Code: Select all

      rv.SetCurrentItemExtraIntProperty(rvepImageWidth, W , True);
      rv.SetCurrentItemExtraIntProperty(rvepImageHeight, H, True);
I've been using the words "size" and "resize" when I should probably be using "resolution." I can resize the images in code or with the mouse no problem. I think what I am wanting to do is to resample the original image, or make a thumbnail from it.

However, I'm beginning to think I'll be better off resizing in an image editor and then pasting it in. Just thought if there's a way to do it in code that would be worth a try.

Thanks Sergey.

Stan
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Save RVF file with resized image

Post by Sergey Tkachenko »

Sorry, I misread your original question.
Yes, when you assign rvepImageWidth or rvepImageHeight property (either in code or resizing with mouse or touchscreen gestures), the image itself is not changed.
If you need it, you need to replace the original image with a resized copy (using SetCurrentPictureInfo or similar method).

Please note that even if you scaled an image down, keeping the original still makes sense to improve quality of
- printing
- displaying on higher DPI screens
standay
Posts: 272
Joined: Fri Jun 18, 2021 3:07 pm

Re: Save RVF file with resized image

Post by standay »

Hi Sergey,

OK, that sounds about like what I thought. I was able to work it with a TBitMap and using Canvas.StretchDraw, but the resulting image is not that good plus transparency drops out on PNGs and so on. I'll resize in a paint program when I have to.

Thanks, this helps to verify things for me!

Stan
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Save RVF file with resized image

Post by Sergey Tkachenko »

TRichView includes high-quality resizing procedures.
Unit RVThumbMaker,

Code: Select all

NewBitmap := RVThumbnailMaker.MakeThumbnail(Graphic, Width, Height);
It supports transparency.
For some graphics it may refuse to resize, in this case it returns nil.
standay
Posts: 272
Joined: Fri Jun 18, 2021 3:07 pm

Re: Save RVF file with resized image

Post by standay »

Hi Sergey,

Finally had time to try this and it seems to work very well. I use PNGs most of the time and it makes a great image reduction and maintains transparency.

Here's the code I'm using in case it will help someone else needing to do the same thing:

Code: Select all

  try
    if (rv.CurItemStyle = rvsPicture) or (rv.CurItemStyle = rvsHotPicture) then
    begin

      //get image info
      rv.GetCurrentPictureInfo( s, gr, RVAlign, ATag );

      //800 is an arbitrary figure I picked as it seems to work best for my purposes.
      //Could be anything wanted:
      if (gr.Width < 800) and (gr.Height < 800) then
      begin
        ShowMessage('Image height and width are already less than 800px');
        exit;
      end;

      //get image sizes:
      w := gr.Width;
      h := gr.Height;
      //set the larger of the 2 to 800px and adjust the other one to match
      //aspect size proportionally:
      ImageSize := ImageAspect(w,h);

      //uses RVThumbMaker:
      gr := RVThumbnailMaker.MakeThumbnail(gr, ImageSize.cx , ImageSize.cy );

      if gr = nil then exit;

      gr.Transparent := true; //need this or no workee for xparent images

      rv.SetCurrentPictureInfo( s, gr, RVAlign, ATag );

    end;
  except
    //do nothing
  end;
Stan
standay
Posts: 272
Joined: Fri Jun 18, 2021 3:07 pm

Re: Save RVF file with resized image

Post by standay »

Hi Sergey,

I spoke to soon. It appears to be working, but it's not.

I can insert the png image and resize it, make the thumbnail, and then set the picture info and all looks as it should, i.e., transparency is intact and the image has in fact been resized. However, if I save the file and then reopen it, size is still OK but the transparency has been lost.

If I just resize the image (by code or by mouse) and save the file and load it again transparency is fine.

Any ideas on what I can do to fix the transparency problem?

Thanks Sergey

Stan
standay
Posts: 272
Joined: Fri Jun 18, 2021 3:07 pm

Re: Save RVF file with resized image

Post by standay »

Hi Sergey,

OK, the following changes seemed to get around the problem:

Code: Select all

      //uses RVThumbMaker:
      gr := RVThumbnailMaker.MakeThumbnail(gr, ImageSize.cx , ImageSize.cy );

      if gr = nil then
      begin
        ShowMessage('Unable to resize this image.');
        exit;
      end;

      //gr.Transparent := RVGraphicHandler.IsTransparent(gr); //no longer needed

      png := TPngImage(RVGraphicHandler.GraphicToPng(gr));

      rv.SetCurrentPictureInfo( s, png, RVAlign, ATag );

      gr.Free;
If anything looks really off please let me know. But this lets me resize as well as maintain transparency.

Stan
Post Reply