TCustomRichView.OnImportPicture

<< Click to display table of contents >>

TCustomRichView.OnImportPicture

Occurs when loading a file or a stream containing links to image files.

type

  TRVImportPictureEvent =

    procedure (Sender: TCustomRichView;

    const Location: TRVUnicodeString; Width, Height: Integer;

    var Graphic: TRVGraphicof object;

 

property OnImportPicture: TRVImportPictureEvent;

(introduced in version 1.8; changed in version 18)

This event may occur:

when loading RTF or DocX. Usually pictures are saved inside RTF/DocX file/stream. But sometimes RTF/DocX contains links to external image files (file names or URLs).

when loading HTML or Markdown

when loading XML (using TRichViewXML component)

when accepting URL to an image as a result of drag&drop, and rvoDragDropPicturesFromLinks is include in EditorOptions.

If these links are local (like 'c:\images\image.bmp'), TRichView can load these files itself. But if images are on the Internet (like 'https://www.trichview.com/images/headers/what_is.gif'), it makes sense to process this event and to download the image.

Input parameters

Location path to the file (local or URL);

Width, Height reserved, equal to 0;

Graphic nil.

Output parameters

Graphic set it to the loaded image. If you leave it equal to nil, TRichView will attempt to load the image itself.

 

If you use RichViewActions, they can use downloader components to download pictures automatically, when loading is initiated by the action (Open, Insert File, Paste and Paste Special actions). This downloader can also be used in OLE drag&drop, see OnBeforeOleDrop and OnAfterOleDrop events.

 

Example: downloading images from http location using Indy (IdHTTP1: TIdHTTP)

uses RVFuncs;

 

{ TMyRichView.OnImportPicture }

procedure TMyForm.MyRichViewImportPicture(Sender: TCustomRichView;

  const Location: TRVUnicodeString; Width, Height: Integer;

  var Graphic: TRVGraphic);

var Stream: TMemoryStream;

begin

  if Pos('http://', AnsiLowerCase(Location))=1 then

  begin

    Stream := TMemoryStream.Create;

    try

      IdHTTP1.Get(Location, Stream);

      Stream.Position := 0;

      Graphic := RVGraphicHandler.LoadFromStream(Stream);

    except

      Graphic := nil;

    end;

    Stream.Free;

  end;

end;