rvico TRichView Reference | How to...

...use third-party graphic classes with RichView

Top  Previous  Next

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.torry.net/vcl/graphics/gif/gifimage.exe (update for D6 and newer: www.trichview.com/resources/thirdparty/gifimage.zip);
TJvGifImage from JEDI's JVCL http://jvcl.sourceforge.net;
Gustavo Huffenbacher Daud's TPngObject pngdelphi.sourceforge.net.

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

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

Controlling automatic insertion of graphics when importing RTF

Sometimes images are inserted automatically (for example, when importing RTF).

Question 1: What graphic classes does RichView use for loading non-standard graphic formats (such as GIF or PNG)?

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

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

This registration is especially necessary if you define this graphic format as HTML graphic format.

Workaround for Delphi bug in constructors of graphic classes

If you use Delphi 5/C++Builder 5 or older, use RV_CreateGraphics (defined in RVFuncs unit) instead of direct call of graphic class constructor.

type

  TRV_CreateGraphicsFunction = 

    function (GraphicClass: TGraphicClass): TGraphic;

var

  RV_CreateGraphics: TRV_CreateGraphicsFunction;

For example, use this code to copy graphic from TPicture to TGraphic:

var pic: TPicture;

  gr: TGraphic;

...

pic := TPicture.Create;

pic.LoadFromFile(FileName);

gr := RV_CreateGraphics(TGraphicClass(pic.Graphic.ClassType));

gr.Assign(pic.Graphic);

pic.Free;

// now you can use gr

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

Exporting graphics in HTML

By default, all images are converted to JPEGs. This is obviously undesirable for formats like GIF and PNG.

You can specify which graphic classes must not be converted.

Use RV_RegisterHTMLGraphicFormat procedure, for example:

uses CRVData;

...

// call this before the first html export

RV_RegisterHTMLGraphicFormat(TGifImage);

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

Specifying PNG class

Specify graphic class for PNG images using RV_RegisterPngGraphic, for example:

uses CRVData;

...

RV_RegisterPngGraphic(TPngObject). 

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


RichView © Sergey Tkachenko