rvico TRichView Reference | TRichView


Top  Previous  Next

Occurs when TRichView saves item containing image to HTML file or stream. This event allows to modify saving procedure for all (or some) images.


  TRVHTMLSaveImageEvent =

    procedure (Sender: TCustomRichView; RVData: TCustomRVData;

      ItemNo: Integer; const Path: String;

      BackgroundColor: TColor; var Location: String;

      var DoDefault: Boolean) of object;


property OnHTMLSaveImage: TRVHTMLSaveImageEvent;

(introduced in version 1.4)

This event is called for the following item types:

pictures, hot-pictures,

bullets, hotspots,

list markers (paragraph bullets) with images,

tables (saving background image),

for background image and cells' background images.

There is more easy-to-use event: OnSaveImage2.

By default:

Images are saved in separate files as Jpegs (or as bitmaps for Delphi2, or if RVDONOTUSEJPEGIMAGE is defined) and have names composed as ImagesPrefix + Number + '.jpg', where

ImagesPrefix parameter of SaveHTML/SaveHTMLEx;

Number some number making this file name unique (image files can override existing ones or not, depending on parameters of SaveHTML/SaveHTMLEx). Bullets and hotspots items having the same image list, image index and background color are saved in the same file (the same is for list markers).

Transparent color of bullets, hotspots and transparent image formats (TIcon, TMetafile, gifs) is replaced with background color (which can be color of component (TRichView.Color/TRVStyle.Color), color of cell (TRVTableCellData.Color) or color of paragraph background (TRVBackroundRect.Color).

You can define formats that must not be converted to Jpeg.

Input Parameters

RVData document containing item that is being saved to image; it can be Sender.RVData, table cell, or RVData of cell inplace-editor.

ItemNo index of this item inside RVData. If this event is called for background image (document or cell), ItemNo=-1.

Path destination directory of HTML file (or Path parameter of SaveHTMLToStream/SaveHTMLToStreamEx).

BackgroundColor color of background below the item (can be ignored, if you can preserve transparency of image)

Location if rvsoUseItemImageFileNames is included in the Options parameter of SaveHTML/SaveHTMLEx, this is a path to the image defined in the rvespImageFileName item property, relative to Path. Otherwise, initial value of this parameter is empty.

Output Parameters

Location set this parameter to file name of image where you saved it. This string will be inserted in HTML file.

DoDefault set to False if you saved this item as image yourself, to disallow default saving. If DoDefault is True, then after calling this event:

if rvsoUseItemImageFileNames is included in the Options parameter of SaveHTML/SaveHTMLEx and value of rvespImageFileName item property is not empty, this value is written in HTML (relative to Path); otherwise

OnSaveImage2 is called (if its handler is assigned); if it is not assigned or OnSaveImage2's DoDefault parameter is True, the default image saving procedure is called.


Inside this event you can use:

Sender.imgSaveNo value which was used as Number for file name for the previously saved image;

RVData.GetNextFileName function returning image file name with the given image prefix and extension:

function GetNextFileName(const ImagesPrefix, Path, Ext: String;

  var imgSaveNo: Integer; OverrideFiles: Boolean): String;


ImagesPrefix the first part of image file name (for example, you can set it to ImagesPrefix parameter of SaveHTML/SaveHTMLEx);

Path path for the image (for example, you can use Path parameter of this event);

Ext file extension, for example '.jpg' (you can use GraphicExtension(TGraphicClass(Graphic.ClassType)));

imgSaveNo this function will use this value incremented one or several times to compose a name of image; returns the incremented value;

OverrideFiles if set to False, this function will check existing files and returns an unique file name (by incrementing imgSaveNo several times)

Return value: full file name of the image. You can use it to save image and assign it to Location parameter of the event (this file name includes path, use ExtractFileName or ExtractRelativePath).


Alternatively, you can use SavePicture.


See also events:



See also

Export to HTML.

TRichView © trichview.com