SaveMarkdown Image Sizes

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

SaveMarkdown Image Sizes

Post by standay »

Hi Sergey,

When I use SaveMarkdown, is there a way to make the image files it creates to be the same size as what is displayed in the original rich view? I use larger images in the rve than what is being displayed so when printing they look OK, but in a mark down file I just want the markdown output image sizes to match the rve display image sizes.

I tried using SaveImage2 and while I can resize the Graphic, it's not resampled from the rve so it shows up cropped in the mark down.

Any ideas appreciated!

Thanks Sergey

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

Re: SaveMarkdown Image Sizes

Post by Sergey Tkachenko »

There is no built-in option to resize images.
And yes, OnSaveImage2 event is the correct solution for this task.

The code may be like this:

Code: Select all

procedure TForm3.RichViewEdit1SaveImage2(Sender: TCustomRichView;
  Graphic: TGraphic; SaveFormat: TRVSaveFormat; const Path,
  ImagePrefix: TRVUnicodeString; var ImageSaveNo: Integer;
  var Location: TRVUnicodeString; var DoDefault: Boolean);
var
  Bmp: TBitmap;
const
  MaxWidth = 300;
begin
  if Graphic.Width <= MaxWidth then
    exit;
  if not ((Graphic is TJpegImage) or (Graphic is TPngImage) or (Graphic is TBitmap)) then
    exit;
  Bmp := TBitmap.Create(MaxWidth, MulDiv(Graphic.Height, MaxWidth, Graphic.Width));
  try
    Bmp.Canvas.StretchDraw(Rect(0, 0, bmp.Width, bmp.Height), Graphic);
    Location := Sender.SavePicture(SaveFormat, ImagePrefix, Path, ImageSaveNo, True, clWhite, Bmp);
    DoDefault := False;
  finally
    Bmp.Free;
  end;
end;
This code checks if the image width is greater than 300 (for bitmaps, png, jpegs). If yes, it creates a bitmap (having width = 300) and stretch-draws the image to it. Then it saves this bitmap. Sender.SavePicture saves bitmap as Jpegs (for markdown and HTML).
standay
Posts: 274
Joined: Fri Jun 18, 2021 3:07 pm

Re: SaveMarkdown Image Sizes

Post by standay »

OK, that's what I figured was the case but thanks for confirming!

Thanks Sergey

Stan
Post Reply