IdxRichEditDocumentImageCollection.Insert(IdxRichEditDocumentPosition,TGraphic) Method
Inserts a new inline image at the specified position in a subdocument.
Declaration
function Insert(const APos: IdxRichEditDocumentPosition; AImage: TGraphic): IdxRichEditDocumentImage;
Parameters
Name | Type |
---|---|
APos | IdxRichEditDocumentPosition |
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 insert it at the APos position into the parent subdocument’s content. For instance, you can insert an inline image at the caret position. 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 Insert 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.Insert(ADocument.CaretPosition, AImageContainer); // Creates a new inline image from the stored bitmap and inserts it at the caret position within the opened document
AImageContainer.Free; // Destroys the Smart Image container to prevent memory leaks
end;