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
SaveMarkdown Image Sizes
-
- Site Admin
- Posts: 17554
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: SaveMarkdown Image Sizes
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:
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).
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;
Re: SaveMarkdown Image Sizes
OK, that's what I figured was the case but thanks for confirming!
Thanks Sergey
Stan
Thanks Sergey
Stan