Pictures in TRichView Documents

<< Click to display table of contents >>

Pictures in TRichView Documents

Pictures

Picture item displays a picture stored in TRVGraphic object.

Delphi VCL has the following standard graphic classes:

TBitmap (stores bitmap (*.bmp), probably with transparency);

TMetafile (stores 32-bit (*.emf) or 16-bit (*.wmf) metafile);

TIcon (stores icon; this class does not work with icons having more than 16 colors properly);

TJpegImage (D3+; stores Jpegs (*.jpg));

TGifImage (D2007+, stores Gifs (*.gif));

TPngImage (D2009+, stores Png (*.png));

TWicImage (D2010+, by default used for Tiff (*.tif) images, but can be used for other graphic formats).

TSkGraphic (Skia4Delphi, stores WebP and WBMP)

TSkSvgGraphic (Skia4Delphi, stores SVG; include RVSkia unit in your project)

In addition, you can use third-party graphic classes.

Delphi FireMonkey has the following graphic classes:

TRVRasterGraphicFM (also accessible as TRVBitmap) (wrapper for TBitmap, stores various raster format; a list of supported format depends on the platform)

TRVSvgImageSkiaFM (Skia4Delphi) (wrapper for TSkSvgBrush, stores SVG, include fmxRVSkiaFM in your project)

Style of this item type: rvsPicture (-3)

For hypertext pictures, see hot-pictures item type.

Methods of TCustomRichView

The following viewer-style methods add item of this type to the end of the document:

AddPicture,

The following viewer-style method changes the main properties of item of this type:

SetPictureInfo

The following method returns main properties of the given item of this type:

GetPictureInfo

Methods of TCustomRichViewEdit

The following editor-style method inserts item of this type at the position of caret:

InsertPicture

The following editor-style methods modify main properties of the item of this type:

SetCurrentPictureInfo,

SetPictureInfoEd

The following method returns main properties of the item of this type at the position of caret:

GetCurrentPictureInfo

Properties

Size

This item type has the following integer properties related to size:

rvepImageWidth, rvepImageHeight stretch the image.

Layout and appearance

This item type has the following integer properties related to layout and appearance:

rvepSpacing padding (spacing between the picture and its border; if a background color is specified, this area is colored);

rvepColor background color;

rvepBorderWidth, rvepBorderColor width and color of a border;

rvepOuterHSpacing, rvepOuterVSpacing horizontal and vertical spacing around the border.

rvepSmoothScaling turn smooth scaling on/off

Memory usage

By default, TRichView frees a graphic object when this item is destroyed, or when a new graphic object is assigned.

However, if rvepShared integer property is nozero, TRichView does not free it.

Rarely used images may be "deactivated", i.e. stored in a memory stream and destroyed (see RichViewMaxPictureCount). Shared images are never deactivated.

Vertical Position

This item type has the following properties affecting vertical position:

VAlign;

extra integer properties: rvepVShift, rvepVShiftAbs.

Resizing

In editor, pictures can be resized with the mouse (except for TIcon). You can forbid mouse resizing by including rvoNoImageResize in EditorOptions. You can forbid resizing for the specific image by assigning 0 to rvepResizable integer property.

Resizing with mouse does not modify the image itself, it changes rvepImageWidth and rvepImageHeight.

OnItemResize event occurs after resizing.

Other properties

This item type has the following specific integer properties:

rvepTransparent, rvepTransparentMode, rvepTransparentColor define transparency in bitmap;

rvepAnimationInterval interval for bitmap animations;

rvepMinHeightOnPage allows printing this image on multiple pages (cannot be applied to metafiles);

rvepNoHTMLImageSize if nonzero, <IMG width> and <IMG height> are not saved in HTML for this image.

This item type has the following specific string properties:

rvespAlt text representation of the image, saved in HTML as <IMG alt> attribute;

rvespImageFileName this property can be saved in HTML file as image location.

Saving and Loading [VCL and LCL]

RichView Format (RVF)

In order to load these items from RVF, you need to register a class of the graphics. RichView does it automatically for the standard item classes. But if you use third-party graphic classes, register them.

For example:

Delphi: RegisterClass(TMyGifImage);

C++Builder: RegisterClass(__classid(TMyGifImage));

Classes of the most of standard graphic formats are automatically registered by TRichView, see the topic about RVGraphicHandler.

If rvfoSavePicturesBody is excluded from RVFOptions, graphic data is not saved in RVF. When loading such RVF files, OnRVFPictureNeeded event occurs. You can use this feature to store images in database or files.

Export to HTML

By default, all pictures are saved as JPEGs. If you want to save pictures of some graphic class without conversion, call RVGraphicHandler.RegisterHTMLGraphicFormat.

For example:

Delphi: RVGraphicHandler.RegisterHTMLGraphicFormat(TMyGifImage);

C++Builder: RVGraphicHandler.RegisterHTMLGraphicFormat(__classid(TMyGifImage));

The standard PNG and GIF formats may be automatically registered by TRichView, see the topic about RVGraphicHandler.

If you want to save pictures in another format, use OnHTMLSaveImage or OnSaveImage2 events.

RTF export

RTFOptions contain options for saving pictures in RTF. Pictures are embedded in RTF, external image files are not created.

Bitmaps are stored as bitmaps. 32-bit metafiles (EMF) are stored as 32-bit or 16-bit (WMF) metafiles.

PNG images are stored as PNG images, if PNG class is specified (see RVGraphicHandler.RegisterPngGraphic).

All other graphic formats are stored as bitmaps, WMF or PNG (except for Jpegs which can be stored as Jpegs).

DocX export

All graphic formats are stored as they are, except for:

bitmaps (they are saved as PNG, if PNG graphic class is defined, see RVGraphicHandler.RegisterPngGraphic;

icons (they are saved as PNG in Delphi 2009+ using TPngImage class)

RTF and DocX Import

You can set RTFReadProperties.IgnorePictures to True, and pictures in RTF/DocX will not be added in RichView.

RTF/DocX can have embedded images and external images (in separate files). In order to load external images, a proper graphic class must be associated with the file extension.

Delphi does it for standard graphic classes automatically, but for some third-party classes you need to do it yourself.

For example:

TPicture.RegisterFileFormat('gif','Gif Image',TMyGifImage);

Read more information in the topic about third-party graphic classes.

See Also...

Working in 256-color display mode;

Animation;

Smooth image scaling.