IdxRichEditDocumentImageCollection.Append(TGraphic) Method
Adds a new inline image to the end of a subdocument.
Declaration
function Append(AImage: TGraphic): IdxRichEditDocumentImage;
Parameters
Name | Type |
---|---|
AImage | TGraphic |
Returns
Type |
---|
IdxRichEditDocumentImage |
Remarks
Call this function and pass an image container as the AImage parameter to create a new inline image from the stored bitmap and append it to the parent subdocument’s content. The function returns nil if the specified source image container is empty; otherwise – returns a newly created inline image.
Note that an inline image’s Office Image container does not support vector images. An Append function call results in the “Invalid operation in GDI+ (Code: 2)” exception if you attempt to use a Smart Image or Smart Glyph image container with an SVG image as the inline image’s source. Call the container’s ConvertToBitmap procedure to rasterize the stored vector image and avoid this error.
uses
..., dxSVGImage; // This unit contains the TdxSVGImageCodec class declaration
//...
procedure TMyForm.cxButton1Click(Sender: TObject);
var
ADocument: IdxRichEditDocument;
AImageContainer: TdxSmartImage;
AFileName: string;
begin
ADocument := dxRichEditControl1.Document;
OpenPictureDialog1.Execute(Handle); // Invokes the "Open" dialog to allow a user to select the source image file
AFileName := OpenPictureDialog1.FileName;
if (AFileName = '') then Exit; // Exits the procedure if a user selects no image
AImageContainer := TdxSmartImage.Create; // Creates a Smart Image container
AImageContainer.LoadFromFile(AFileName);
if (AImageContainer.ImageCodec = TdxSVGImageCodec) then // If the container has loaded an SVG image
AImageContainer.ConvertToBitmap; // Rasterizes the vector image
ADocument.Images.Append(AImageContainer); // Creates a new inline image from the stored bitmap and appends it to the opened document
AImageContainer.Free; // Destroys the Smart Image container to prevent memory leaks
end;
See Also