如何从 TOleContainer 中提取元文件? [英] How to extract metafile from TOleContainer?

查看:28
本文介绍了如何从 TOleContainer 中提取元文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 TOleContainer 控件的 Delphi (BDS 2006) 应用程序.它内部有一个 OLE 对象,来自 MS Office 2003 的 MS Equation 公式(名称Equation.3").

I have a Delphi (BDS 2006) application with TOleContainer control. It has an OLE object inside, MS Equation formula (name 'Equation.3') from MS Office 2003.

如何从公式图像中提取矢量元文件以将其插入网页或其他不支持 OLE 的文档?

How can I extract the vector metafile from the formula image to insert it into web-page or some other document without OLE support?

TOleContainer 内部只有Equation.3"对象,没有其他可能性.我尝试使用 .Copy 方法使其通过剪贴板,但它复制了一个空图像.

TOleContainer has only 'Equation.3' objects inside, no other possibilities. I've tried to use .Copy method to make it through clipboard, but it's copied an empty image.

推荐答案

OLE Con​​tainer 有底层IOLEObject 接口,你可以访问.您可以将其传递给 OLEDraw 函数你自己的画布.您可以使用位图或元文件画布,然后以您需要的格式保存图像.

OLE Container has on underlying IOLEObject interface you can access. You can pass that to the OLEDraw function with your own canvas. You could use either a Bitmap or Metafile canvas and then save out the image in the format you need.

OleDraw(OleContainer.OleObjectInterface, DVASPECT_CONTENT, Bmp.Canvas.Handle, R);

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;

这篇关于如何从 TOleContainer 中提取元文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆