如何:加载和显示图元文件

继承自 Image 类的 Metafile 类提供用于记录、显示和检查矢量图像的方法。

示例

若要在屏幕上显示矢量图像(图元文件),需要一个 Metafile 对象和一个 Graphics 对象。 将文件的名称(或流)传递给 Metafile 构造函数。 创建 Metafile 对象后,将该 Metafile 对象传递给 Graphics 对象的 DrawImage 方法。

该示例从 EMF(增强型图元文件)文件创建一个 Metafile 对象,然后绘制图像,其左上角位于 (60, 10)。

下图显示了在指定位置绘制的图元文件。

Screenshot showing image position.

Metafile metafile = new Metafile("SampleMetafile.emf");
e.Graphics.DrawImage(metafile, 60, 10);
Dim metafile As New Metafile("SampleMetafile.emf")
e.Graphics.DrawImage(metafile, 60, 10)

编译代码

前面的示例专用于 Windows 窗体,它需要 PaintEventArgse,后者是 Paint 事件处理程序的参数。

另请参阅