Class EmfRecorderGraphics2D
Namespace: Aspose.Imaging.FileFormats.Emf.Graphics
Assembly: Aspose.Imaging.dll (25.7.0)
The Emf recorder graphics
public sealed class EmfRecorderGraphics2D : MetafileRecorderGraphics2D
{
}
Inheritance
object ← MetafileRecorderGraphics2D ← EmfRecorderGraphics2D
Inherited Members
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(Rectangle, Size, Size)
Initializes a new instance of the Aspose.Imaging.FileFormats.Emf.Graphics.EmfRecorderGraphics2D class.
public EmfRecorderGraphics2D(Rectangle frame, Size deviceSize, Size deviceSizeMm)
{
}
Parameters
frame
Rectangle
The frame.
deviceSize
Size
Size of the device.
deviceSizeMm
Size
The device size mm.
Examples
This example shows how to create a EMF image and draw some geometric shapes on it using EmfRecorderGraphics2D.
string dir = "c:\\temp\\";
int deviceWidth = 600;
int deviceHeight = 400;
int deviceWidthMm = (int)(deviceWidth / 100f);
int deviceHeightMm = (int)(deviceHeight / 100f);
Aspose.Imaging.Rectangle frame = new Aspose.Imaging.Rectangle(0, 0, deviceWidth, deviceHeight);
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));
graphics.DrawRectangle(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Black, 1), 0, 0, deviceWidth, deviceHeight);
graphics.FillRectangle(new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.WhiteSmoke), new Aspose.Imaging.Rectangle(10, 10, 580, 380));
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);
graphics.DrawArc(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Blue, 2), new Aspose.Imaging.Rectangle(0, 0, 200, 200), 90, 270);
graphics.FillPie(new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.LightSkyBlue), new Aspose.Imaging.Rectangle(0, 0, 150, 150), 90, 270);
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));
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);
}
graphics.DrawString("Hello World!", new Aspose.Imaging.Font("Arial", 48, Aspose.Imaging.FontStyle.Regular), Aspose.Imaging.Color.DarkRed, 200, 300);
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)),
});
graphics.FillPath(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Green, 2), new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Yellow), pathToFill);
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),
});
graphics.DrawPath(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Orange, 5), pathToDraw);
Aspose.Imaging.ImageOptions.SvgRasterizationOptions rasterizationOptions = new Aspose.Imaging.ImageOptions.SvgRasterizationOptions();
Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();
saveOptions.VectorRasterizationOptions = rasterizationOptions;
using (Aspose.Imaging.FileFormats.Emf.EmfImage emfImage = graphics.EndRecording())
{
emfImage.Save(dir + "test.output.emf");
}
Properties
BackgroundMode
Gets or sets the background mode.
public EmfBackgroundMode BackgroundMode
{
get;
set;
}
Property Value
Methods
EndRecording()
Ends the recording.
public EmfImage EndRecording()
{
using (var emfStream = new MemoryStream())
{
this.recorder.Close();
var emfData = this.recorder.GetEmfData();
emfData.Save(emfStream, System.Drawing.Imaging.ImageFormat.Emf);
return new EmfImage(emfStream.ToArray());
}
}
Returns
The result image.
Examples
This example shows how to create a EMF image and draw some geometric shapes on it using EmfRecorderGraphics2D.
string dir = "c:\\temp\\";
int deviceWidth = 600;
int deviceHeight = 400;
int deviceWidthMm = (int)(deviceWidth / 100f);
int deviceHeightMm = (int)(deviceHeight / 100f);
Aspose.Imaging.Rectangle frame = new Aspose.Imaging.Rectangle(0, 0, deviceWidth, deviceHeight);
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));
graphics.DrawRectangle(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Black, 1), 0, 0, deviceWidth, deviceHeight);
graphics.FillRectangle(new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.WhiteSmoke), new Aspose.Imaging.Rectangle(10, 10, 580, 380));
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);
graphics.DrawArc(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Blue, 2), new Aspose.Imaging.Rectangle(0, 0, 200, 200), 90, 270);
graphics.FillPie(new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.LightSkyBlue), new Aspose.Imaging.Rectangle(0, 0, 150, 150), 90, 270);
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));
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);
}
graphics.DrawString("Hello World!", new Aspose.Imaging.Font("Arial", 48, Aspose.Imaging.FontStyle.Regular), Aspose.Imaging.Color.DarkRed, 200, 300);
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)),
});
graphics.FillPath(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Green, 2), new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Yellow), pathToFill);
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),
});
graphics.DrawPath(new Aspose.Imaging.Pen(Aspose.Imaging.Color.Orange, 5), pathToDraw);
Aspose.Imaging.ImageOptions.SvgRasterizationOptions rasterizationOptions = new Aspose.Imaging.ImageOptions.SvgRasterizationOptions();
Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();
saveOptions.VectorRasterizationOptions = rasterizationOptions;
using (Aspose.Imaging.FileFormats.Emf.EmfImage emfImage = graphics.EndRecording())
{
emfImage.Save(dir + "test.output.emf");
}
FromEmfImage(EmfImage)
Gets an instance of the Aspose.Imaging.FileFormats.Emf.Graphics.EmfRecorderGraphics2D containing all records from the Emf image.
public static EmfRecorderGraphics2D FromEmfImage(EmfImage emfImage)
{
return new EmfRecorderGraphics2D(emfImage);
}
Parameters
emfImage
EmfImage
The Emf image to read records from.
Returns
An instance of the Aspose.Imaging.FileFormats.Emf.Graphics.EmfRecorderGraphics2D
Examples
This example shows how to load a EMF image from a file and draw a text string over it.
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);
int width = emfImage.Width;
int height = emfImage.Height;
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);
graphics.SetTransform(transform);
graphics.DrawString("WATERMARK", new Aspose.Imaging.Font("Courier New", emFontSize), Aspose.Imaging.Color.LightPink, 0, 0);
using (Aspose.Imaging.FileFormats.Emf.EmfImage scaledEmfImage = graphics.EndRecording())
{
scaledEmfImage.Save(dir + "test.scaled.emf");
}
}