Aspose.Imaging for .NET如何使用代码创建 EMF图像元文件

作者:控件中国网   出处:控件中国网   2016-11-01 14:41:27   阅读:13

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
Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D graphics = new Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D(new Aspose.Imaging.Rectangle(0, 0, 100, 100), 96);
 
// Define background color
graphics.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke;
 
//Init
// Create an instance of Imaging Pen class and mention its color.
Aspose.Imaging.Pen pen = new Aspose.Imaging.Pen(Aspose.Imaging.Color.Blue);
 
// Create an instance of Imaging Brush class and mention its color.
Aspose.Imaging.Brush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.YellowGreen);
 
//Polygon
// Fill polygon by calling FillPolygon method and passing parameters brush and points.
graphics.FillPolygon(brush, new Aspose.Imaging.Point[] { new Aspose.Imaging.Point(2, 2), new Aspose.Imaging.Point(20, 20), new Aspose.Imaging.Point(20, 2) });
 
// Draw a polygon by calling DrawPolygon method and passing parameters pen and points.
graphics.DrawPolygon(pen, new Aspose.Imaging.Point[] { new Aspose.Imaging.Point(2, 2), new Aspose.Imaging.Point(20, 20), new Aspose.Imaging.Point(20, 2) });
 
//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
pen.DashStyle = Aspose.Imaging.DashStyle.Dot;
 
// Set color of the pen
pen.Color = Aspose.Imaging.Color.Black;
 
// 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
pen.DashStyle = Aspose.Imaging.DashStyle.Solid;
pen.Color = Aspose.Imaging.Color.Red;
 
// Draw an CubicBezier by calling DrawCubicBezier method and passing parameters pen and points.
graphics.DrawCubicBezier(pen, new Aspose.Imaging.Point(10, 25), new Aspose.Imaging.Point(20, 50), new Aspose.Imaging.Point(30, 50), new Aspose.Imaging.Point(40, 25));
 
//Image
// Create an Instance of Image class.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"TextureBrushPattern.png"))
{
    // Cast the instance of image class to RasterImage.
    Aspose.Imaging.RasterImage rasterImage = image as Aspose.Imaging.RasterImage;
    if (rasterImage != null)
    {
        // Draw an image by calling DrawImage method and passing parameters rasterimage and point.
        graphics.DrawImage(rasterImage, new Aspose.Imaging.Point(50, 50));
    }
}
 
//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.
graphics.DrawLine(pen, new Aspose.Imaging.Point(2, 98), new Aspose.Imaging.Point(2, 50));
 
//Pie
// Define settings of the brush object.
brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Green);
pen.Color = Aspose.Imaging.Color.DarkGoldenrod;
 
// 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);
 
pen.Color = Aspose.Imaging.Color.AliceBlue;
 
//Polyline
// Draw Polyline by calling DrawPolyline method and passing parameters pen and points.
graphics.DrawPolyline(pen, new Aspose.Imaging.Point[] { new Aspose.Imaging.Point(50, 40), new Aspose.Imaging.Point(75, 40), new Aspose.Imaging.Point(75, 45), new Aspose.Imaging.Point(50, 45) });
 
// For having Strings
// Create an instance of Font class.
Aspose.Imaging.Font font = new Aspose.Imaging.Font("Arial", 16);
 
// 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");
}
 
Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat