Class EmfRecorderGraphics2D

Class EmfRecorderGraphics2D

Названий на: Aspose.Imaging.FileFormats.Emf.Graphics Асамблея: Aspose.Imaging.dll (25.4.0)

Графічні записи EMF

public sealed class EmfRecorderGraphics2D : MetafileRecorderGraphics2D

Inheritance

object MetafileRecorderGraphics2D EmfRecorderGraphics2D

Нападні члени

MetafileRecorderGraphics2D.Clear() , MetafileRecorderGraphics2D.DrawArc(Pen, Rectangle, float, float) , MetafileRecorderGraphics2D.DrawCubicBezier(Pen, Point, Point, Point, Point) , MetafileRecorderGraphics2D.DrawPolyCubicBezier(Pen, Point[]) , MetafileRecorderGraphics2D.DrawEllipse(Pen, Rectangle) , MetafileRecorderGraphics2D.FillEllipse(Brush, Rectangle) , MetafileRecorderGraphics2D.DrawImage(RasterImage, Point) , MetafileRecorderGraphics2D.DrawImage(RasterImage, Rectangle, Rectangle, GraphicsUnit) , MetafileRecorderGraphics2D.DrawImage(byte[], Rectangle, GraphicsUnit) , MetafileRecorderGraphics2D.DrawImage(Stream, Rectangle, GraphicsUnit) , MetafileRecorderGraphics2D.DrawLine(Pen, int, int, int, int) , MetafileRecorderGraphics2D.DrawLine(Pen, Point, Point) , MetafileRecorderGraphics2D.DrawPolyline(Pen, Point[]) , MetafileRecorderGraphics2D.DrawPath(Pen, GraphicsPath) , MetafileRecorderGraphics2D.FillPath(Pen, Brush, GraphicsPath) , MetafileRecorderGraphics2D.DrawPie(Pen, Rectangle, float, float) , MetafileRecorderGraphics2D.FillPie(Brush, Rectangle, float, float) , MetafileRecorderGraphics2D.DrawPolygon(Pen, Point[]) , MetafileRecorderGraphics2D.FillPolygon(Brush, Point[]) , MetafileRecorderGraphics2D.FillPolygon(Brush, Point[], FillMode) , MetafileRecorderGraphics2D.DrawRectangle(Pen, int, int, int, int) , MetafileRecorderGraphics2D.DrawRectangle(Pen, Rectangle) , MetafileRecorderGraphics2D.FillRectangle(Brush, Rectangle) , MetafileRecorderGraphics2D.DrawString(string, Font, Color, int, int) , MetafileRecorderGraphics2D.DrawString(string, Font, Color, int, int, float) , MetafileRecorderGraphics2D.ExcludeClip(Rectangle) , MetafileRecorderGraphics2D.ExcludeClip(Region) , MetafileRecorderGraphics2D.IntersectClip(RectangleF) , MetafileRecorderGraphics2D.IntersectClip(Region) , MetafileRecorderGraphics2D.ResetClip() , MetafileRecorderGraphics2D.MultiplyTransform(Matrix) , MetafileRecorderGraphics2D.MultiplyTransform(Matrix, MatrixOrder) , MetafileRecorderGraphics2D.TranslateTransform(float, float) , MetafileRecorderGraphics2D.TranslateTransform(float, float, MatrixOrder) , MetafileRecorderGraphics2D.RotateTransform(float) , MetafileRecorderGraphics2D.RotateTransform(float, PointF, MatrixOrder) , MetafileRecorderGraphics2D.ScaleTransform(float, float) , MetafileRecorderGraphics2D.ScaleTransform(float, float, MatrixOrder) , MetafileRecorderGraphics2D.GetTransform() , MetafileRecorderGraphics2D.SetTransform(Matrix) , MetafileRecorderGraphics2D.Clip , MetafileRecorderGraphics2D.ClipBounds , MetafileRecorderGraphics2D.BackgroundColor , object.GetType() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Constructors

Створення EmfRecorderGraphics2D(Розмір, розмір і прямий)

Ініціалізація нової інстанції класу Aspose.Imaging.FileFormats.Emf.Graphics. EmfRecorderGrafics2D.

public EmfRecorderGraphics2D(Rectangle frame, Size deviceSize, Size deviceSizeMm)

Parameters

frame Rectangle

Це рамка.

deviceSize Size

Розмір пристрою .

deviceSizeMm Size

Розмір пристрою мм.

Examples

Цей приклад показує, як створити зображення EMF і малювати деякі геометричні форми на ньому за допомогою EmfRecorderGraphics2D.

string dir = "c:\\temp\\";

                                                                                                                         // The image size in pixels
                                                                                                                         int deviceWidth = 600;
                                                                                                                         int deviceHeight = 400;

                                                                                                                         // The image size in millimiters
                                                                                                                         int deviceWidthMm = (int)(deviceWidth / 100f);
                                                                                                                         int deviceHeightMm = (int)(deviceHeight / 100f);

                                                                                                                         Aspose.Imaging.Rectangle frame = new Aspose.Imaging.Rectangle(0, 0, deviceWidth, deviceHeight);

                                                                                                                         // Create a EMF image.
                                                                                                                         Aspose.Imaging.FileFormats.Emf.Graphics.EmfRecorderGraphics2D graphics =
                                                                                                                             new Aspose.Imaging.FileFormats.Emf.Graphics.EmfRecorderGraphics2D(
                                                                                                                                 frame,
                                                                                                                                 new Aspose.Imaging.Size(deviceWidth, deviceHeight),
                                                                                                                                 new Aspose.Imaging.Size(deviceWidthMm, deviceHeightMm));

                                                                                                                         // Draw a black rectangle along the image borders using a 1-pixel-wide black pen.
                                                                                                                         graphics.DrawRectangle(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Black, 1), 0, 0, deviceWidth, deviceHeight);

                                                                                                                         // Fill a rectangle with the color of white-smoke.
                                                                                                                         graphics.FillRectangle(new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.WhiteSmoke), new Aspose.Imaging.Rectangle(10, 10, 580, 380));

                                                                                                                         // Draw two diagonal lines using a 1-pixel-wide darkgreen pen.
                                                                                                                         graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.DarkGreen, 1), 0, 0, deviceWidth, deviceHeight);
                                                                                                                         graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.DarkGreen, 1), 0, deviceHeight, deviceWidth, 0);

                                                                                                                         // Draw an arc within the rectangle {0, 0, 200, 200} using a 2-pixel-wide blue pen.
                                                                                                                         graphics.DrawArc(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Blue, 2), new Aspose.Imaging.Rectangle(0, 0, 200, 200), 90, 270);

                                                                                                                         // Fill an arc
                                                                                                                         graphics.FillPie(new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.LightSkyBlue), new Aspose.Imaging.Rectangle(0, 0, 150, 150), 90, 270);

                                                                                                                         // Draw a cubic bezier using a 2-pixel-wide red pen.
                                                                                                                         graphics.DrawCubicBezier(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Red, 2),
                                                                                                                             new Aspose.Imaging.Point(0, 0),
                                                                                                                             new Aspose.Imaging.Point(200, 133),
                                                                                                                             new Aspose.Imaging.Point(400, 166),
                                                                                                                             new Aspose.Imaging.Point(600, 400));

                                                                                                                         // Draw a raster image of the specified size at the specified location.
                                                                                                                         // The image is scaled to fit the desired rectangle.
                                                                                                                         using (Aspose.Imaging.RasterImage imageToDraw = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(dir + "sample.bmp"))
                                                                                                                         {
                                                                                                                             graphics.DrawImage(imageToDraw,
                                                                                                                                 new Aspose.Imaging.Rectangle(400, 200, 100, 50),
                                                                                                                                 new Aspose.Imaging.Rectangle(0, 0, deviceWidth, deviceHeight),
                                                                                                                                 Aspose.Imaging.GraphicsUnit.Pixel);
                                                                                                                         }

                                                                                                                         // Draw a text string
                                                                                                                         graphics.DrawString("Hello World!", new Aspose.Imaging.Font("Arial", 48, Aspose.Imaging.FontStyle.Regular), Aspose.Imaging.Color.DarkRed, 200, 300);

                                                                                                                         // Create a path to fill
                                                                                                                         Aspose.Imaging.Figure figureToFill = new Aspose.Imaging.Figure();
                                                                                                                         figureToFill.IsClosed = true;

                                                                                                                         Aspose.Imaging.GraphicsPath pathToFill = new Aspose.Imaging.GraphicsPath();
                                                                                                                         pathToFill.AddFigure(figureToFill);

                                                                                                                         figureToFill.AddShapes(new Shape[]
                                                                                                                             {
                                                                                                                                 new Aspose.Imaging.Shapes.ArcShape(new Aspose.Imaging.Rectangle(400, 0, 200, 100), 45, 300),
                                                                                                                                 new Aspose.Imaging.Shapes.BezierShape(
                                                                                                                                     new Aspose.Imaging.PointF[]
                                                                                                                                     {
                                                                                                                                         new Aspose.Imaging.PointF(300, 200),
                                                                                                                                         new Aspose.Imaging.PointF(400, 200),
                                                                                                                                         new Aspose.Imaging.PointF(500, 100),
                                                                                                                                         new Aspose.Imaging.PointF(600, 200),
                                                                                                                                     }),
                                                                                                                                 new Aspose.Imaging.Shapes.PolygonShape(
                                                                                                                                     new Aspose.Imaging.PointF[]
                                                                                                                                     {
                                                                                                                                         new Aspose.Imaging.PointF(300, 100),
                                                                                                                                     }),
                                                                                                                                 new Aspose.Imaging.Shapes.RectangleShape(new Aspose.Imaging.RectangleF(0, 100, 200, 200)),
                                                                                                                             });

                                                                                                                         // Fill the path using a yellow brush and a green pen to draw outline
                                                                                                                         graphics.FillPath(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Green, 2), new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Yellow), pathToFill);

                                                                                                                         // Create a path to draw
                                                                                                                         Aspose.Imaging.GraphicsPath pathToDraw = new Aspose.Imaging.GraphicsPath();
                                                                                                                         Aspose.Imaging.Figure figureToDraw = new Aspose.Imaging.Figure();
                                                                                                                         pathToDraw.AddFigure(figureToDraw);

                                                                                                                         figureToDraw.AddShapes(new Aspose.Imaging.Shape[]
                                                                                                                             {
                                                                                                                                 new Aspose.Imaging.Shapes.ArcShape(new Aspose.Imaging.RectangleF(200, 200, 200, 200), 0, 360),
                                                                                                                             });

                                                                                                                         // Draw the path using a 5-pixel-wide orange pen.
                                                                                                                         graphics.DrawPath(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Orange, 5), pathToDraw);

                                                                                                                         // In order to rasterize SVG we need to specify rasterization options.
                                                                                                                         Aspose.Imaging.ImageOptions.SvgRasterizationOptions rasterizationOptions = new Aspose.Imaging.ImageOptions.SvgRasterizationOptions();
                                                                                                                         Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();
                                                                                                                         saveOptions.VectorRasterizationOptions = rasterizationOptions;

                                                                                                                         // Get the final WMF image which includes all drawing commands
                                                                                                                         using (Aspose.Imaging.FileFormats.Emf.EmfImage emfImage = graphics.EndRecording())
                                                                                                                         {
                                                                                                                             emfImage.Save(dir + "test.output.emf");
                                                                                                                         }

Properties

BackgroundMode

Приймати або встановити режим фону.

public EmfBackgroundMode BackgroundMode { get; set; }

вартість нерухомості

EmfBackgroundMode

Methods

EndRecording()

Закінчився запис.

public EmfImage EndRecording()

Returns

EmfImage

Результат зображення.

Examples

Цей приклад показує, як створити зображення EMF і малювати деякі геометричні форми на ньому за допомогою EmfRecorderGraphics2D.

string dir = "c:\\temp\\";

                                                                                                                         // The image size in pixels
                                                                                                                         int deviceWidth = 600;
                                                                                                                         int deviceHeight = 400;

                                                                                                                         // The image size in millimiters
                                                                                                                         int deviceWidthMm = (int)(deviceWidth / 100f);
                                                                                                                         int deviceHeightMm = (int)(deviceHeight / 100f);

                                                                                                                         Aspose.Imaging.Rectangle frame = new Aspose.Imaging.Rectangle(0, 0, deviceWidth, deviceHeight);

                                                                                                                         // Create a EMF image.
                                                                                                                         Aspose.Imaging.FileFormats.Emf.Graphics.EmfRecorderGraphics2D graphics =
                                                                                                                             new Aspose.Imaging.FileFormats.Emf.Graphics.EmfRecorderGraphics2D(
                                                                                                                                 frame,
                                                                                                                                 new Aspose.Imaging.Size(deviceWidth, deviceHeight),
                                                                                                                                 new Aspose.Imaging.Size(deviceWidthMm, deviceHeightMm));

                                                                                                                         // Draw a black rectangle along the image borders using a 1-pixel-wide black pen.
                                                                                                                         graphics.DrawRectangle(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Black, 1), 0, 0, deviceWidth, deviceHeight);

                                                                                                                         // Fill a rectangle with the color of white-smoke.
                                                                                                                         graphics.FillRectangle(new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.WhiteSmoke), new Aspose.Imaging.Rectangle(10, 10, 580, 380));

                                                                                                                         // Draw two diagonal lines using a 1-pixel-wide darkgreen pen.
                                                                                                                         graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.DarkGreen, 1), 0, 0, deviceWidth, deviceHeight);
                                                                                                                         graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.DarkGreen, 1), 0, deviceHeight, deviceWidth, 0);

                                                                                                                         // Draw an arc within the rectangle {0, 0, 200, 200} using a 2-pixel-wide blue pen.
                                                                                                                         graphics.DrawArc(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Blue, 2), new Aspose.Imaging.Rectangle(0, 0, 200, 200), 90, 270);

                                                                                                                         // Fill an arc
                                                                                                                         graphics.FillPie(new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.LightSkyBlue), new Aspose.Imaging.Rectangle(0, 0, 150, 150), 90, 270);

                                                                                                                         // Draw a cubic bezier using a 2-pixel-wide red pen.
                                                                                                                         graphics.DrawCubicBezier(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Red, 2),
                                                                                                                             new Aspose.Imaging.Point(0, 0),
                                                                                                                             new Aspose.Imaging.Point(200, 133),
                                                                                                                             new Aspose.Imaging.Point(400, 166),
                                                                                                                             new Aspose.Imaging.Point(600, 400));

                                                                                                                         // Draw a raster image of the specified size at the specified location.
                                                                                                                         // The image is scaled to fit the desired rectangle.
                                                                                                                         using (Aspose.Imaging.RasterImage imageToDraw = (Aspose.Imaging.RasterImage)Aspose.Imaging.Image.Load(dir + "sample.bmp"))
                                                                                                                         {
                                                                                                                             graphics.DrawImage(imageToDraw,
                                                                                                                                 new Aspose.Imaging.Rectangle(400, 200, 100, 50),
                                                                                                                                 new Aspose.Imaging.Rectangle(0, 0, deviceWidth, deviceHeight),
                                                                                                                                 Aspose.Imaging.GraphicsUnit.Pixel);
                                                                                                                         }

                                                                                                                         // Draw a text string
                                                                                                                         graphics.DrawString("Hello World!", new Aspose.Imaging.Font("Arial", 48, Aspose.Imaging.FontStyle.Regular), Aspose.Imaging.Color.DarkRed, 200, 300);

                                                                                                                         // Create a path to fill
                                                                                                                         Aspose.Imaging.Figure figureToFill = new Aspose.Imaging.Figure();
                                                                                                                         figureToFill.IsClosed = true;

                                                                                                                         Aspose.Imaging.GraphicsPath pathToFill = new Aspose.Imaging.GraphicsPath();
                                                                                                                         pathToFill.AddFigure(figureToFill);

                                                                                                                         figureToFill.AddShapes(new Shape[]
                                                                                                                             {
                                                                                                                                 new Aspose.Imaging.Shapes.ArcShape(new Aspose.Imaging.Rectangle(400, 0, 200, 100), 45, 300),
                                                                                                                                 new Aspose.Imaging.Shapes.BezierShape(
                                                                                                                                     new Aspose.Imaging.PointF[]
                                                                                                                                     {
                                                                                                                                         new Aspose.Imaging.PointF(300, 200),
                                                                                                                                         new Aspose.Imaging.PointF(400, 200),
                                                                                                                                         new Aspose.Imaging.PointF(500, 100),
                                                                                                                                         new Aspose.Imaging.PointF(600, 200),
                                                                                                                                     }),
                                                                                                                                 new Aspose.Imaging.Shapes.PolygonShape(
                                                                                                                                     new Aspose.Imaging.PointF[]
                                                                                                                                     {
                                                                                                                                         new Aspose.Imaging.PointF(300, 100),
                                                                                                                                     }),
                                                                                                                                 new Aspose.Imaging.Shapes.RectangleShape(new Aspose.Imaging.RectangleF(0, 100, 200, 200)),
                                                                                                                             });

                                                                                                                         // Fill the path using a yellow brush and a green pen to draw outline
                                                                                                                         graphics.FillPath(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Green, 2), new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Yellow), pathToFill);

                                                                                                                         // Create a path to draw
                                                                                                                         Aspose.Imaging.GraphicsPath pathToDraw = new Aspose.Imaging.GraphicsPath();
                                                                                                                         Aspose.Imaging.Figure figureToDraw = new Aspose.Imaging.Figure();
                                                                                                                         pathToDraw.AddFigure(figureToDraw);

                                                                                                                         figureToDraw.AddShapes(new Aspose.Imaging.Shape[]
                                                                                                                             {
                                                                                                                                 new Aspose.Imaging.Shapes.ArcShape(new Aspose.Imaging.RectangleF(200, 200, 200, 200), 0, 360),
                                                                                                                             });

                                                                                                                         // Draw the path using a 5-pixel-wide orange pen.
                                                                                                                         graphics.DrawPath(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Orange, 5), pathToDraw);

                                                                                                                         // In order to rasterize SVG we need to specify rasterization options.
                                                                                                                         Aspose.Imaging.ImageOptions.SvgRasterizationOptions rasterizationOptions = new Aspose.Imaging.ImageOptions.SvgRasterizationOptions();
                                                                                                                         Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();
                                                                                                                         saveOptions.VectorRasterizationOptions = rasterizationOptions;

                                                                                                                         // Get the final WMF image which includes all drawing commands
                                                                                                                         using (Aspose.Imaging.FileFormats.Emf.EmfImage emfImage = graphics.EndRecording())
                                                                                                                         {
                                                                                                                             emfImage.Save(dir + "test.output.emf");
                                                                                                                         }

FromEmfImage(EmfImage)

Отримає приклад Aspose.Imaging.FileFormats.Emf.Graphics.EMfRecorderGrafics2D, що містить всі записи з зображення EMF.

public static EmfRecorderGraphics2D FromEmfImage(EmfImage emfImage)

Parameters

emfImage EmfImage

Зображення EMF для читання записів з.

Returns

EmfRecorderGraphics2D

Приклад Aspose.Imaging.FileFormats.Emf.Graphics.EMfRecorderGrafics2D

Examples

Цей приклад показує, як завантажити зображення EMF з файлу і витягнути над ним текстовий ряд.

string dir = "c:\\temp\\";

                                                                                                 using (Aspose.Imaging.FileFormats.Emf.EmfImage emfImage = (Aspose.Imaging.FileFormats.Emf.EmfImage)Aspose.Imaging.Image.Load(dir + "test.emf"))
                                                                                                 {
                                                                                                     Aspose.Imaging.FileFormats.Emf.Graphics.EmfRecorderGraphics2D graphics =
                                                                                                         Aspose.Imaging.FileFormats.Emf.Graphics.EmfRecorderGraphics2D.FromEmfImage(emfImage);

                                                                                                     // First, get the image size
                                                                                                     int width = emfImage.Width;
                                                                                                     int height = emfImage.Height;

                                                                                                     // Second, calculate a transformation to put a text string along the main diagonal of the image -
                                                                                                     // from the upper-left to the bootom-right corner.
                                                                                                     float emFontSize = 96f;
                                                                                                     float d = (float)System.Math.Sqrt(width * width + height * height);
                                                                                                     float scaleFactor = d / (emFontSize * 5f);

                                                                                                     float tan = ((float)height) / width;                
                                                                                                     double radians = System.Math.Atan(tan);
                                                                                                     double degrees = (180 * radians) / System.Math.PI;

                                                                                                     Aspose.Imaging.Matrix transform = new Aspose.Imaging.Matrix();
                                                                                                     transform.Rotate((float)degrees);
                                                                                                     transform.Scale(scaleFactor, scaleFactor);

                                                                                                     // Then, set the transform.
                                                                                                     graphics.SetTransform(transform);

                                                                                                     // Finally, put a watermark (text string of pink color) along the main diagonal.
                                                                                                     graphics.DrawString("WATERMARK", new Aspose.Imaging.Font("Courier New", emFontSize), Aspose.Imaging.Color.LightPink, 0, 0/*, (float)degrees*/);

                                                                                                     // Save the image with watermark to another EMF file.
                                                                                                     using (Aspose.Imaging.FileFormats.Emf.EmfImage scaledEmfImage = graphics.EndRecording())
                                                                                                     {
                                                                                                         scaledEmfImage.Save(dir + "test.scaled.emf");
                                                                                                     }
                                                                                                 }

Дивіться також

MetafileRecorderGraphics2D

 Українська