How to use third-party graphic classes with TRichView [VCL and LCL]

<< Click to display table of contents >>

How to use third-party graphic classes with TRichView [VCL and LCL]

About FireMonkey

All the information below is about VCL and LCL.

In FireMonkey, graphic classes are inherited from TRVGraphicFM.

Using third party graphic classes

You can use graphic classes created by third party developers.

These classes can be used just like standard classes (TBitmap, TIcon, TMetafile, TJpegImage).

You can add picture in a document using AddPictureEx or InsertPicture.

Example:

gif: TGifImage;

...

gif := TGifImage.Create;

gif.LoadFromFile('demo.gif');

editor.InsertPicture('Demo', gif, rvvaBaseLine);

For example, you can use free graphic classes:

Anders Melander's TGifImage (www.trichview.com/resources/thirdparty/gifimage.zip) (useful for Delphi 2006 and older)

TJvGifImage from JEDI's JVCL https://wiki.delphi-jedi.org/ (useful for Delphi 2006 and older)

Gustavo Huffenbacher Daud's TPngObject www.trichview.com/resources/thirdparty/pngimage.zip (useful for Delphi 2007 and older)

Starting from Delphi 2007, an advanced version of Anders Melander's TGifImage is included in VCL, so TGifImage becomes a standard graphic class.

Starting from Delphi 2009, TPngImage is included in VCL.

Gif animation

To support animation, assign TCustomRichView.AnimationMode = rvaniOnFormat.

The following units must be included in your projects:

RVGifAnimate for Anders Melander's TGifImage;

RVJvGifAnimate for TJvGifImage from JEDI's JVCL;

RVGifAnimate2007 for standard Delphi TGifImage (in Delphi 2007 or newer).

See also: animation in TRichView

Controlling automatic insertion of graphics when importing RTF, DocX, HTML, and Markdown

Loading external image files

Sometimes images are inserted automatically (for example, when importing images referred from RTF, DocX, Markdown or HTML).

Question: What graphic classes does TRichView use for loading graphic formats (such as GIF or PNG)?

Answer: TRichView uses the graphic class which is registered for the given file extension.

First, TRichView tried to detect image format by the file content, and choose the appropriate graphic class for this format.

If the first part was not succeed, it uses associations between file extensions and graphic classes.

If a third party creator has not associated his graphic class with the extension, you can do it yourself with TPicture.RegisterFileFormat:

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

Loading images embedded in RTF, DocX or HTML

When importing images contained inside RTF or DocX, TRichView uses graphic classes, specified as default graphic classes for graphic format. See TRVGraphicHandlder.SetDefaultGraphicClass.

When importing images contained inside HTML (base64-encoded), TRichView detects graphic format by content.

Workaround for Delphi bug in constructors of graphic classes (Delphi 5)

If you use Delphi 5, use RVGraphicHandler.CreateGraphic (defined in RVFuncs unit) instead of direct call of graphic class constructor.

It is not necessary if you use Delphi 6/C++Builder 6 or newer.

Exporting graphics to HTML

By default, all non-web images are converted to JPEGs. It may be undesirable for some other formats.

You can specify which graphic classes must not be converted.

Use RVGraphicHandler.RegisterHTMLGraphicFormat procedure, for example:

uses RVGrHandler;

...

// call this before the first html export

RVGraphicHandler.RegisterHTMLGraphicFormat(TMyGifImage);

This registration affects only images of the given format. Other formats will be converted to JPEGs.

TRichView registers the following classes as HTML graphic formats automatically:

standard TPngImage (for Delphi 2009+);

standard TGifImage (for Delphi 2007+), if you include RVGifAnimate2007 unit in your project;

Anders Melander's TGifImage, if you include RVGifAnimate unit in your project;

TJvGifImage from JEDI's JVCL, if you include RVJvGifAnimate unit in your project.

TPortableNetworkGraphic (for Lazarus).

 

Specifying PNG class

Specify graphic class for PNG images using Use RVGraphicHandler.RegisterPngGraphic, for example:

uses RVFuncs;

...

RVGraphicHandler.RegisterPngGraphic(TPngObject). 

It allows loading PNG images from RTF files and saving PNG images to RTF and DocX files without converting to bitmaps or metafiles.

In Delphi 2009+, TRichView automatically registers the standard TPngImage as a PNG class.

Specifying JPEG class

Specify graphic class for Jpeg images using Use RVGraphicHandler.RegisterJpegGraphic, for example:

uses RVFuncs;

...

RVGraphicHandler.RegisterJpegGraphic(TMyJpegImage). 

If you do not call this method, TRichView uses TJPEGImage.

This class is used when loading JPEG images embedded in RTF.

Using DevExpress graphic classes

If you uncomment RVUSEDXPNGIMAGE in RV_Defs.inc, TRichView supports DevExpress classes:

TcxPngImage for Png

TdxSmartImage for Bitmap, Jpeg, Tiff, Gif, Svg images.

TcxPngImage becomes a default Png class for TRichView, but TdxSmartImage does not become a default Jpeg class, unless you call RVGraphicHandler.RegisterJpegGraphic explicitly.