trichview.com

trichview.support.examples




Example: How to use OnSaveComponentToFile for saving TImage in RTF


Return to index


Author

Message

Sergey Tkachenko

Posted: 01/30/2004 19:38:09


Be default, controls inserted in document are not saved in RTF. TRichView

provides the OnSaveComponentToFile event which you can use to save them

yourself.


The code below shows how to save TImage. It uses some undocumented methods,

but I think it's clear enough.


uses CRVData, RVItem.


procedure TForm3.RichViewEdit1SaveComponentToFile(Sender: TCustomRichView;

  Path: String; SaveMe: TPersistent; SaveFormat: TRVSaveFormat;

  var OutStr: String);


  function GetTwipsPerPixel: Double;

  var DC: HDC;

  begin

    DC := CreateCompatibleDC(0);

    if RichViewPixelsPerInch>0 then

      Result := (72*20) / RichViewPixelsPerInch

    else

      Result := (72*20) / GetDeviceCaps(DC, LOGPIXELSY);

    DeleteDC(DC);

  end;


var img: TImage;

    Stream: TStringStream;

begin

  if (SaveFormat<>rvsfRTF) or not (SaveMe is TImage) then

    exit;

  img := TImage(SaveMe);

  Stream := TStringStream.Create('');

  RVSaveImageToRTF(Stream, GetTwipsPerPixel, img.Picture.Graphic,

    img.Width, img.Height, Sender.RTFOptions);

  OutStr := Stream.DataString;

  Stream.Free;

end;





Powered by ABC Amber Outlook Express Converter