Aspose.Imaging for .NET是一款丰富的图像处理和转换以及编辑的无图形界面类库,在新发布的16.10版本中控件提供了WmfRecorderGraphics2D类用于专门创建EMF元文件图片,具体的创建方法可以参考下面的代码:
/ WmfRecorderGraphics2D class provides you the frame or canvas to draw shapes on it.
// Create an instance of WmfRecorderGraphics2D class. The constructor takes in 2 parameters:
// 1. Instance of Imaging Rectangle class
// 2. An integer value for inches
// Define background color
//Init
// Create an instance of Imaging Pen class and mention its color.
// Create an instance of Imaging Brush class and mention its color.
//Polygon
// Fill polygon by calling FillPolygon method and passing parameters brush and points.
// Draw a polygon by calling DrawPolygon method and passing parameters pen and points.
//Ellipse
// Create an instance of HatchBrush class set different properties.
brush = new HatchBrush() { HatchStyle = HatchStyle.Cross, BackgroundColor =
Aspose.Imaging.Color.White, ForegroundColor =
Aspose.Imaging.Color.Silver };
// Fill ellipse by calling FillEllipse method and passing parameters brush and an instance of Imaging Rectangle class.
graphics.FillEllipse(brush, new
Aspose.Imaging.Rectangle(25, 2, 20, 20));
// Draw an ellipse by calling DrawEllipse method and passing parameters pen and an instance of Imaging Rectangle class.
graphics.DrawEllipse(pen, new
Aspose.Imaging.Rectangle(25, 2, 20, 20));
//Arc
// Define pen style by setting DashStyle value
// Set color of the pen
// Draw an Arc by calling DrawArc method and passing parameters pen and an instance of Imaging Rectangle class.
graphics.DrawArc(pen, new
Aspose.Imaging.Rectangle(50, 2, 20, 20), 0, 180);
//CubicBezier
// Draw an CubicBezier by calling DrawCubicBezier method and passing parameters pen and points.
//Image
// Create an Instance of Image class.
{
// Cast the instance of image class to RasterImage.
if (rasterImage != null)
{
// Draw an image by calling DrawImage method and passing parameters rasterimage and point.
}
}
//Line
// Draw a line by calling DrawLine method and passing x,y coordinates of 1st point and same for 2nd point along with color infor as Pen.
//Pie
// Define settings of the brush object.
// Fill pie by calling FillPie method and passing parameters brush and an instance of Imaging Rectangle class.
graphics.FillPie(brush, new
Aspose.Imaging.Rectangle(2, 38, 20, 20), 0, 45);
// Draw pie by calling DrawPie method and passing parameters pen and an instance of Imaging Rectangle class.
graphics.DrawPie(pen, new
Aspose.Imaging.Rectangle(2, 38, 20, 20), 0, 45);
//Polyline
// Draw Polyline by calling DrawPolyline method and passing parameters pen and points.
// For having Strings
// Create an instance of Font class.
// Draw String by calling DrawString method and passing parameters string to display, color and X & Y coordinates.
graphics.DrawString("Aspose", font,
Aspose.Imaging.Color.Blue, 25, 75);
// Call end recording of graphics object and save WMF image by calling Save method.
using (
Aspose.Imaging.FileFormats.Wmf.WmfImage image = graphics.EndRecording())
{
image.Save(@"TestGraphicDrawing.wmf");
}