TCustomRichView.OnHTMLSaveImage

<< Click to display table of contents >>

TCustomRichView.OnHTMLSaveImage

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

type

  TRVHTMLSaveImageEvent =

    procedure (Sender: TCustomRichView; RVData: TCustomRVData;

      ItemNo: Integer; const Path: TRVUnicodeString;

      BackgroundColor: TRVColorvar Location: String;

      var DoDefault: Boolean) of object;

 

property OnHTMLSaveImage: TRVHTMLSaveImageEvent;

(introduced in version 1.4; changed in version 16)

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. Png, Gif, Jpeg images are saved in the corresponding format. Images of non-web formats are saved as Jpeg images. If you do not want to convert some additional image class to Jpeg, you can register it as HTML graphic format usiing RVGraphicHandler. File names of saved images are composed as ImagesPrefix + Number + '.' + FileExtension, where

ImagesPrefix HTMLSaveProperties.ImagesPrefix;

Number some number making this file name unique (image files can override existing ones or not, depending on rvhtmlsioOverrideImages in HTMLSaveProperties.ImageOptions).

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).

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

Location if rvhtmlsioUseItemImageFileNames is included in HTMLSaveProperties.ImageOptions, 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 rvhtmlsioUseItemImageFileNames is included in HTMLSaveProperties.ImageOptions 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: TRVUnicodeString;

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

where

ImagesPrefix the first part of image file name (for example, you can set it to HTMLSaveProperties.ImagesPrefix);

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

Ext file extension, for example '.jpg' (you can use RVGraphicHandler.GetGraphicExt() or GetGraphicExtByType());

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:

OnSaveImage2;

OnSaveItemToFile.

See also

Export to HTML.