About Linked Images

<< Click to Display Table of Contents >>

Navigation:  Programming > Objects > Images > C) Work with images >

About Linked Images

Linked images use the string propetry StreamName to identify their contents. If this property is not an empty string, the binary image data will not be saved in a document format which otherwise allows embedding, such as RTF and WPT. To HTML images can only be saved if a "StreamName" is provided.

 

The event OnHTTPRequestImage is used to load the image data for images placed in HTML code and also for linked images loaded in RTF or WPT format. This event should be used to load images from a database which are only referenced in the text blob.

 

Please read the FAQ at

  http://wpcubed.com/forum/viewtopic.php?p=3287#3287

 

The event OnPrepareImageforSaving can be used to create image files (or database records) for images which are embedded.

 

This example code will create new files for all images which are not embedded. They will also be compressed.

 

procedure TForm1.WPRichText1PrepareImageforSaving(

 RTFData: TWPRTFDataCollectionBase; Writer: TWPCustomTextWriter;

 TextObject: TWPTextObj; var DontSave: Boolean);

begin

if ConvertEmebddedtoLinked.Checked then

begin

  if TextObject.IsImage and (TextObject.ObjRef.StreamName='') then

  begin

      TextObject.ObjRef.StreamName :=

         ExtractFileName(

             TextObject.ObjRef.SaveToFile( Writer.SavePath, 'Test', '%d', true)

         );

  end;

end;

end;

 

This example handler for OnHTTPRequestImage is used to load images through Indy.

 

procedure TForm1.WPRichText1RequestHTTPImage(RTFData: TWPRTFDataCollection;

 Reader: TWPCustomTextReader; const LoadPath, URL: String;

 TextObject: TWPTextObj; var Ok: Boolean);

var stream : TMemoryStream;

   loadurl : string;

begin

if pos('http:',lowercase(URL))>0 then

     loadurl := URL

else loadurl := LoadPath + URL;

 

 stream := TMemoryStream.Create;

try

   Panel2.Caption := URL;

  try

     Application.ProcessMessages;

    // this example uses INDY

     IdHTTP1.Get(loadurl,stream);

  except

    on e : Exception do Panel2.Caption := URL + '-->' + e.Message;

  end;

  if stream.Size>0 then

  try

      TextObject.LoadObjFromStream(URL,stream);

  except

      on e : Exception do Panel2.Caption := URL + '-->' + e.Message;

  end;

   ok := TRUE;

  if ok then Panel2.Caption := '';

   Application.ProcessMessages;

finally

   stream.Free;

end;

end;