The OLE container has the basic IOLEObject interface, which you can access. You can pass this OLEDraw using your own canvas. You can use the Bitmap or Metafile canvas, and then save the image in the format you need.
OleDraw (OleContainer.OleObjectInterface, DVASPECT_CONTENT, Bmp.Canvas.Handle, R);
{ DrawOleOnBmp --------------------------------------------------------------------------- Take a OleObject and draw it to a bitmap canvas. The bitmap will be sized to match the normal size of the OLE Object. } procedure DrawOleOnBmp(Ole: IOleObject; Bmp: TBitmap); var ViewObject2: IViewObject2; ViewSize: TPoint; AdjustedSize: TPoint; DC: HDC; R: TRect; begin if Succeeded(Ole.QueryInterface(IViewObject2, ViewObject2)) then begin ViewObject2.GetExtent(DVASPECT_CONTENT, -1, nil, ViewSize); DC := GetDC(0); AdjustedSize.X := MulDiv(ViewSize.X, GetDeviceCaps(DC, LOGPIXELSX), 2540); AdjustedSize.Y := MulDiv(ViewSize.Y, GetDeviceCaps(DC, LOGPIXELSY), 2540); ReleaseDC(0, DC); Bmp.Height := AdjustedSize.Y; Bmp.Width := AdjustedSize.X; SetRect(R, 0, 0, Bmp.Width, Bmp.Height); OleDraw(Ole, DVASPECT_CONTENT, Bmp.Canvas.Handle, R); end else begin raise Exception.Create('Could not get the IViewObject2 interfact on the OleObject'); end; end;
source share