[How to] How to use PNG and GIF images in TRichView

Demos, code samples. Only questions related to the existing topics are allowed here.
Sergey Tkachenko
Site Admin
Posts: 13637
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Thu Dec 08, 2011 6:12 pm

There are no procedures for unregistering. Everything is cleaned up when the application exits.

Sergey Tkachenko
Site Admin
Posts: 13637
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Fri Jun 07, 2013 2:52 pm

The first message in this topic is updated for compatibility with TRichView 14.5+:
- now, TRichView uses TPngImage automatically in Delphi 2009+ (unless you define RVDONOTUSEPNGIMAGE in RV_Defs.inc)
- RVGraphicHandler should be used instead of the old functions

Sergey Tkachenko
Site Admin
Posts: 13637
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: [How to] How to use PNG and GIF images in TRichView

Post by Sergey Tkachenko » Tue Nov 21, 2017 5:50 pm

This information is useful for users of Delphi 2007 and older. New versions of Delphi have a built-in TPngImage class, it is supported by TRichView automatically.

Once again about using TPngObject.
Information in the first post of this topic describes all necessary steps except for allowing high-quality resizing for PNG images.
You need to add code allowing thumbnails (high-quality sizing) for TPngObject.
The complete initialization code for TPngObject is:

Code: Select all

uses
  PngImage, RVGrHandler, RVThumbMaker;

...

type
  TMyGraphicHandler = class (TRVGraphicHandler)
  public
    function IsTransparent(Graphic: TGraphic): Boolean; override;
  end;

function TMyGraphicHandler.IsTransparent(Graphic: TGraphic): Boolean;
begin
  if Graphic is TPNGObject then
    Result := Graphic.Transparent
  else
    Result := inherited IsTransparent(Graphic);
end;

procedure InitPngObject;
begin
  RVGraphicHandler.Free;
  RVGraphicHandler := TMyGraphicHandler.Create;
  RegisterClass(TPngObject);
  RVGraphicHandler.RegisterHTMLGraphicFormat(TPngObject);
  RVGraphicHandler.RegisterPngGraphic(TPngObject);
  RVThumbnailMaker.AllowThumbnailsFor(TPNGObject);
end;

initialization
  InitPngObject;

end;

Post Reply