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

TJpegImage (stores Jpeg (*.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)

The RVF format can contain the names of classes used to represent images. To load these items from an RVF, you must register the graphics class. TRichView does this automatically for standard graphics classes. However, if you use third-party graphics classes, register them; see the topic about RVGraphicHandler.

For example:

Delphi: RegisterClass(TMyGifImage);

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

If a class name isn't saved in the RVF or the class isn't registered, TRichView chooses a suitable graphic class based on the graphic's content. An option is available in which stored class names are ignored and content-based selection is always used (rvfoIgnoreGraphicClasses in RVFOptions property).

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 images, except those considered to be in web formats, are saved in JPEG format.

TRichView treats an image as being in a web format if it recognizes it as JPEG, PNG, GIF, SVG, or WebP.

If you want to save images of a specific graphic class without conversion (that is, treat them as web formats), 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.

Bitmap images are saved as bitmap or PNG.

32-bit metafiles (EMF) are saved as 32-bit or 16-bit (WMF) metafiles.

PNG and JPEG images can be saved without format conversion.

All other image formats are saved as bitmap, WMF, or PNG.

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.