Class MetafileRecorderGraphics2D
Nama dari : Aspose.Imaging.FileFormats.Emf.Graphics Pengumpulan: Aspose.Imaging.dll (25.4.0)
Grafis rekaman metafil
public abstract class MetafileRecorderGraphics2D
Inheritance
object ← MetafileRecorderGraphics2D
Derived
EmfRecorderGraphics2D , WmfRecorderGraphics2D
anggota yang diwarisi
object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Properties
BackgroundColor
Dapatkan atau menetapkan warna latar belakang.
public Color BackgroundColor { get; set; }
Nilai Properti
BackgroundMode
Dapatkan atau menetapkan mode latar belakang.
protected int BackgroundMode { get; set; }
Nilai Properti
Clip
Dapatkan atau menetapkan Wilayah yang membatasi wilayah menggambar Grafik ini
public Region Clip { get; set; }
Nilai Properti
ClipBounds
Dapatkan batas klip.
public RectangleF ClipBounds { get; }
Nilai Properti
Methods
Clear()
Membersihkan status objek grafis
public void Clear()
DrawArc(Pen, rektangle, float, float)
Ia menggambarkan arc yang mewakili bagian dari ellipse yang ditentukan oleh struktur rektangle.
public void DrawArc(Pen pen, Rectangle rect, float startAngle, float arcAngle)
Parameters
pen
Pen
Pen yang menentukan warna, lebar, dan gaya angka.
rect
Rectangle
Perbatasan dari Ellipse
startAngle
float
Sudut dalam derajat diukur secara jam dari x-axis ke titik permulaan arc.
arcAngle
float
Sudut dalam derajat diukur dengan cara jam dari parameter StartAngle sampai titik akhir dari arc.
Examples
Contoh ini menunjukkan cara membuat gambar WMF dan menggambar beberapa bentuk geometrik menggunakan WmfRecorderGraphics2D.
string dir = "c:\\temp\\";
int imageWidth = 600;
int imageHeight = 400;
// This is the default screen resolution.
int dpi = 96;
Aspose.Imaging.Rectangle frame = new Aspose.Imaging.Rectangle(0, 0, imageWidth, imageHeight);
// Create a WMF image.
Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D graphics =
new Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D(frame, dpi);
// 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, imageWidth, imageHeight);
// 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, imageWidth, imageHeight);
graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.DarkGreen, 1), 0, imageHeight, imageWidth, 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, imageWidth, imageHeight),
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.Wmf.WmfImage wmfImage = graphics.EndRecording())
{
wmfImage.Save(dir + "test.output.wmf");
}
Contoh ini menunjukkan bagaimana untuk membuat gambar EMF dan menggambar beberapa bentuk geometrik di atasnya menggunakan 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");
}
DrawCubicBezier(Pen, titik, titik, titik dan titik)
Menarik dari kubik bezier.
public void DrawCubicBezier(Pen pen, Point pt1, Point pt2, Point pt3, Point pt4)
Parameters
pen
Pen
Pen yang menentukan warna, lebar, dan gaya angka.
pt1
Point
titik awal dari kurva.
pt2
Point
Titik kontrol pertama untuk kurva.
pt3
Point
Titik kontrol kedua untuk kurva.
pt4
Point
titik akhir dari kurva.
Examples
Contoh ini menunjukkan cara membuat gambar WMF dan menggambar beberapa bentuk geometrik menggunakan WmfRecorderGraphics2D.
string dir = "c:\\temp\\";
int imageWidth = 600;
int imageHeight = 400;
// This is the default screen resolution.
int dpi = 96;
Aspose.Imaging.Rectangle frame = new Aspose.Imaging.Rectangle(0, 0, imageWidth, imageHeight);
// Create a WMF image.
Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D graphics =
new Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D(frame, dpi);
// 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, imageWidth, imageHeight);
// 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, imageWidth, imageHeight);
graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.DarkGreen, 1), 0, imageHeight, imageWidth, 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, imageWidth, imageHeight),
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.Wmf.WmfImage wmfImage = graphics.EndRecording())
{
wmfImage.Save(dir + "test.output.wmf");
}
Contoh ini menunjukkan bagaimana untuk membuat gambar EMF dan menggambar beberapa bentuk geometrik di atasnya menggunakan 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");
}
DrawEllipse(Pen, rektangle)
Menariknya Ellipse
public void DrawEllipse(Pen pen, Rectangle rect)
Parameters
pen
Pen
Pen yang menentukan warna, lebar, dan gaya angka.
rect
Rectangle
Perbatasan dari Ellipse
DrawImage(Perbedaan, Point)
Menarik gambar yang ditentukan, menggunakan ukuran fisik asli, di lokasi yang ditentukan.
public void DrawImage(RasterImage image, Point location)
Parameters
image
RasterImage
Gambar yang harus dicetak.
location
Point
Lokasi sudut kiri atas gambar yang ditarik.
DrawImage(RasterImage, Rectangle, Rectangle, Grafik)
Menarik bagian yang ditentukan dari Gambar yang ditentukan di lokasi yang ditentukan dan dengan ukuran yang ditentukan.
public void DrawImage(RasterImage image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit)
Parameters
image
RasterImage
Gambar yang harus dicetak.
destRect
Rectangle
Struktur rektangle yang menentukan lokasi dan ukuran gambar yang ditarik.
srcRect
Rectangle
Struktur rektangle yang menentukan bagian dari objek gambar untuk dicetak.
srcUnit
GraphicsUnit
Unit pengukuran yang digunakan oleh parameter srcRect.
Examples
Contoh ini menunjukkan cara membuat gambar WMF dan menggambar beberapa bentuk geometrik menggunakan WmfRecorderGraphics2D.
string dir = "c:\\temp\\";
int imageWidth = 600;
int imageHeight = 400;
// This is the default screen resolution.
int dpi = 96;
Aspose.Imaging.Rectangle frame = new Aspose.Imaging.Rectangle(0, 0, imageWidth, imageHeight);
// Create a WMF image.
Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D graphics =
new Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D(frame, dpi);
// 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, imageWidth, imageHeight);
// 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, imageWidth, imageHeight);
graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.DarkGreen, 1), 0, imageHeight, imageWidth, 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, imageWidth, imageHeight),
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.Wmf.WmfImage wmfImage = graphics.EndRecording())
{
wmfImage.Save(dir + "test.output.wmf");
}
Contoh ini menunjukkan bagaimana untuk membuat gambar EMF dan menggambar beberapa bentuk geometrik di atasnya menggunakan 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");
}
Exceptions
srcUnit;Support hanya unit Pixel
DrawImage(byte[ ], Rectangle, GraphicsUnit)
Menarik gambar tersebut.
public void DrawImage(byte[] imageBytes, Rectangle destRect, GraphicsUnit srcUnit)
Parameters
imageBytes
byte
[ ]
Gambar yang berisi byte.
destRect
Rectangle
yang benar.
srcUnit
GraphicsUnit
unit sumbernya.
DrawImage(Stream, Rectangle dan Graphics)
Menarik gambar tersebut.
public void DrawImage(Stream stream, Rectangle destRect, GraphicsUnit srcUnit)
Parameters
stream
Stream
dan aliran tersebut.
destRect
Rectangle
yang benar.
srcUnit
GraphicsUnit
unit sumbernya.
DrawLine(Pen, int, int, int, int)
menggerakkan garis tersebut.
public void DrawLine(Pen pen, int x1, int y1, int x2, int y2)
Parameters
pen
Pen
Pen yang menentukan warna, lebar, dan gaya angka.
x1
int
Koordinat x dari titik pertama.
y1
int
koordinat dari titik pertama.
x2
int
Koordinat X dari titik kedua.
y2
int
koordinat dari titik kedua.
Examples
Contoh ini menunjukkan cara membuat gambar WMF dan menggambar beberapa bentuk geometrik menggunakan WmfRecorderGraphics2D.
string dir = "c:\\temp\\";
int imageWidth = 600;
int imageHeight = 400;
// This is the default screen resolution.
int dpi = 96;
Aspose.Imaging.Rectangle frame = new Aspose.Imaging.Rectangle(0, 0, imageWidth, imageHeight);
// Create a WMF image.
Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D graphics =
new Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D(frame, dpi);
// 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, imageWidth, imageHeight);
// 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, imageWidth, imageHeight);
graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.DarkGreen, 1), 0, imageHeight, imageWidth, 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, imageWidth, imageHeight),
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.Wmf.WmfImage wmfImage = graphics.EndRecording())
{
wmfImage.Save(dir + "test.output.wmf");
}
Contoh ini menunjukkan bagaimana untuk membuat gambar EMF dan menggambar beberapa bentuk geometrik di atasnya menggunakan 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");
}
DrawLine(Pen, titik dan titik)
menggerakkan garis tersebut.
public void DrawLine(Pen pen, Point pt1, Point pt2)
Parameters
pen
Pen
Pen yang menentukan warna, lebar, dan gaya angka.
pt1
Point
Titik pertama .
pt2
Point
Dan titik kedua.
DrawPath(Pen dan GraphicsPath)
menggerakkan jalan.
public void DrawPath(Pen pen, GraphicsPath path)
Parameters
pen
Pen
Pen yang menentukan warna, lebar, dan gaya angka.
path
GraphicsPath
Jalan untuk menggambar.
Examples
Contoh ini menunjukkan cara membuat gambar WMF dan menggambar beberapa bentuk geometrik menggunakan WmfRecorderGraphics2D.
string dir = "c:\\temp\\";
int imageWidth = 600;
int imageHeight = 400;
// This is the default screen resolution.
int dpi = 96;
Aspose.Imaging.Rectangle frame = new Aspose.Imaging.Rectangle(0, 0, imageWidth, imageHeight);
// Create a WMF image.
Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D graphics =
new Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D(frame, dpi);
// 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, imageWidth, imageHeight);
// 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, imageWidth, imageHeight);
graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.DarkGreen, 1), 0, imageHeight, imageWidth, 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, imageWidth, imageHeight),
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.Wmf.WmfImage wmfImage = graphics.EndRecording())
{
wmfImage.Save(dir + "test.output.wmf");
}
Contoh ini menunjukkan bagaimana untuk membuat gambar EMF dan menggambar beberapa bentuk geometrik di atasnya menggunakan 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");
}
DrawPie(Pen, rektangle, float, float)
Menarik kaki itu.
public void DrawPie(Pen pen, Rectangle rect, float startAngle, float sweepAngle)
Parameters
pen
Pen
Pen yang menentukan warna, lebar, dan gaya angka.
rect
Rectangle
Perbatasan dari Ellipse
startAngle
float
Sudut dalam derajat diukur secara jam dari x-axis ke titik permulaan arc.
sweepAngle
float
Sudut dalam derajat diukur dengan cara jam dari parameter StartAngle sampai titik akhir dari arc.
DrawPolyCubicBezier(Pen, titik[])
Menggandakan poli kubik bezier.
public void DrawPolyCubicBezier(Pen pen, Point[] points)
Parameters
pen
Pen
Pen yang menentukan warna, lebar, dan gaya angka.
points
Point
[ ]
dengan poin.
Exceptions
Jumlah poin dalam urutan harus lebih dari 3 plus 1, seperti 4, 7 atau 10.
DrawPolygon(Pen, titik[])
Menggerakkan polygon
public void DrawPolygon(Pen pen, Point[] points)
Parameters
pen
Pen
Pen yang menentukan warna, lebar, dan gaya angka.
points
Point
[ ]
dengan poin.
DrawPolyline(Pen, titik[])
Menggunakan polilin.
public void DrawPolyline(Pen pen, Point[] points)
Parameters
pen
Pen
Pen yang menentukan warna, lebar, dan gaya angka.
points
Point
[ ]
dengan poin.
DrawRectangle(Pen, int, int, int, int)
menggerakkan rektangle.
public void DrawRectangle(Pen pen, int x, int y, int width, int height)
Parameters
pen
Pen
Pen yang menentukan warna, lebar, dan gaya angka.
x
int
Koordinat x dari sudut kiri atas rektangul untuk dicetak.
y
int
Y-koordinat sudut kiri atas rektangul untuk dicetak.
width
int
Ketebalan rektangul untuk dicetak.
height
int
Ketinggian rektangle untuk dicetak.
Examples
Contoh ini menunjukkan cara membuat gambar WMF dan menggambar beberapa bentuk geometrik menggunakan WmfRecorderGraphics2D.
string dir = "c:\\temp\\";
int imageWidth = 600;
int imageHeight = 400;
// This is the default screen resolution.
int dpi = 96;
Aspose.Imaging.Rectangle frame = new Aspose.Imaging.Rectangle(0, 0, imageWidth, imageHeight);
// Create a WMF image.
Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D graphics =
new Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D(frame, dpi);
// 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, imageWidth, imageHeight);
// 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, imageWidth, imageHeight);
graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.DarkGreen, 1), 0, imageHeight, imageWidth, 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, imageWidth, imageHeight),
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.Wmf.WmfImage wmfImage = graphics.EndRecording())
{
wmfImage.Save(dir + "test.output.wmf");
}
Contoh ini menunjukkan bagaimana untuk membuat gambar EMF dan menggambar beberapa bentuk geometrik di atasnya menggunakan 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");
}
DrawRectangle(Pen, rektangle)
menggerakkan rektangle.
public void DrawRectangle(Pen pen, Rectangle rectangle)
Parameters
pen
Pen
Pen yang menentukan warna, lebar, dan gaya angka.
rectangle
Rectangle
rektangle untuk dicetak.
DrawString(string, font, warna, int, int)
Menggandakan string.
public void DrawString(string @string, Font font, Color color, int x, int y)
Parameters
string
string
Untuk string.
font
Font
Font yang menentukan format teks dari string.
color
Color
warna teks tersebut.
x
int
Koordinat x dari sudut kiri atas teks yang ditarik.
y
int
Y-koordinat dari sudut kiri atas teks yang ditarik.
Examples
Contoh ini menunjukkan cara memuat gambar EMF dari file dan menggambar string teks di atasnya.
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");
}
}
Contoh ini menunjukkan cara membuat gambar WMF dan menggambar beberapa bentuk geometrik menggunakan WmfRecorderGraphics2D.
string dir = "c:\\temp\\";
int imageWidth = 600;
int imageHeight = 400;
// This is the default screen resolution.
int dpi = 96;
Aspose.Imaging.Rectangle frame = new Aspose.Imaging.Rectangle(0, 0, imageWidth, imageHeight);
// Create a WMF image.
Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D graphics =
new Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D(frame, dpi);
// 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, imageWidth, imageHeight);
// 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, imageWidth, imageHeight);
graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.DarkGreen, 1), 0, imageHeight, imageWidth, 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, imageWidth, imageHeight),
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.Wmf.WmfImage wmfImage = graphics.EndRecording())
{
wmfImage.Save(dir + "test.output.wmf");
}
Contoh ini menunjukkan bagaimana untuk membuat gambar EMF dan menggambar beberapa bentuk geometrik di atasnya menggunakan 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");
}
DrawString(string, font, warna, int, int, float)
Menggandakan string.
public void DrawString(string @string, Font font, Color color, int x, int y, float angle)
Parameters
string
string
Untuk string.
font
Font
Font yang menentukan format teks dari string.
color
Color
warna teks tersebut.
x
int
Koordinat x dari sudut kiri atas teks yang ditarik.
y
int
Y-koordinat dari sudut kiri atas teks yang ditarik.
angle
float
Sudut dalam derajat, antara vector melarikan diri dan x-axis perangkat.Vektor melarikan diri adalah paralel dengan garis dasar satu baris teks.
ExcludeClip(Rectangle)
Mengemas kini daerah klip grafis ini untuk mengecualikan area yang ditentukan oleh struktur rektangle.
public void ExcludeClip(Rectangle rect)
Parameters
rect
Rectangle
Struktur rektangle yang menentukan rektangle untuk dikecualikan dari daerah klip.
ExcludeClip(Region)
Memperbarui wilayah klip grafis ini untuk mengecualikan area yang ditentukan oleh wilayah.
public void ExcludeClip(Region region)
Parameters
region
Region
Wilayah yang mendefinisikan wilayah untuk dikecualikan dari wilayah klip.
FillEllipse(Reka bentuk, rectangle)
Mengisi Ellipse
public void FillEllipse(Brush brush, Rectangle rect)
Parameters
brush
Brush
Pembersih yang menentukan karakteristik pengisian.
rect
Rectangle
Perbatasan dari Ellipse
FillPath(Pen, Perisai, GraphicsPath)
mengisi jalur tersebut.
public void FillPath(Pen pen, Brush brush, GraphicsPath path)
Parameters
pen
Pen
Pen yang menentukan warna, lebar, dan gaya angka.
brush
Brush
Pembersih yang menentukan karakteristik pengisian.
path
GraphicsPath
Jalan untuk diisi.
Examples
Contoh ini menunjukkan cara membuat gambar WMF dan menggambar beberapa bentuk geometrik menggunakan WmfRecorderGraphics2D.
string dir = "c:\\temp\\";
int imageWidth = 600;
int imageHeight = 400;
// This is the default screen resolution.
int dpi = 96;
Aspose.Imaging.Rectangle frame = new Aspose.Imaging.Rectangle(0, 0, imageWidth, imageHeight);
// Create a WMF image.
Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D graphics =
new Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D(frame, dpi);
// 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, imageWidth, imageHeight);
// 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, imageWidth, imageHeight);
graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.DarkGreen, 1), 0, imageHeight, imageWidth, 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, imageWidth, imageHeight),
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.Wmf.WmfImage wmfImage = graphics.EndRecording())
{
wmfImage.Save(dir + "test.output.wmf");
}
Contoh ini menunjukkan bagaimana untuk membuat gambar EMF dan menggambar beberapa bentuk geometrik di atasnya menggunakan 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");
}
FillPie(Bercukur, rektangle, float, float)
mengisi kaki.
public void FillPie(Brush brush, Rectangle rect, float startAngle, float sweepAngle)
Parameters
brush
Brush
Pembersih yang menentukan karakteristik pengisian.
rect
Rectangle
Perbatasan dari Ellipse
startAngle
float
Sudut dalam derajat diukur secara jam dari x-axis ke titik permulaan arc.
sweepAngle
float
Sudut dalam derajat diukur dengan cara jam dari parameter StartAngle sampai titik akhir dari arc.
Examples
Contoh ini menunjukkan cara membuat gambar WMF dan menggambar beberapa bentuk geometrik menggunakan WmfRecorderGraphics2D.
string dir = "c:\\temp\\";
int imageWidth = 600;
int imageHeight = 400;
// This is the default screen resolution.
int dpi = 96;
Aspose.Imaging.Rectangle frame = new Aspose.Imaging.Rectangle(0, 0, imageWidth, imageHeight);
// Create a WMF image.
Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D graphics =
new Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D(frame, dpi);
// 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, imageWidth, imageHeight);
// 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, imageWidth, imageHeight);
graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.DarkGreen, 1), 0, imageHeight, imageWidth, 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, imageWidth, imageHeight),
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.Wmf.WmfImage wmfImage = graphics.EndRecording())
{
wmfImage.Save(dir + "test.output.wmf");
}
Contoh ini menunjukkan bagaimana untuk membuat gambar EMF dan menggambar beberapa bentuk geometrik di atasnya menggunakan 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");
}
FillPolygon(Tumbuh, titik[])
Mengisi Polygon
public void FillPolygon(Brush brush, Point[] points)
Parameters
brush
Brush
Pembersih yang menentukan karakteristik pengisian.
points
Point
[ ]
dengan poin.
FillPolygon(Tumbuh, titik[ ], dan FillMode)
Mengisi Polygon
public void FillPolygon(Brush brush, Point[] points, FillMode fillMode)
Parameters
brush
Brush
Pembersih yang menentukan karakteristik pengisian.
points
Point
[ ]
dengan poin.
fillMode
FillMode
mode yang diisi.
FillRectangle(Reka bentuk, rectangle)
mengisi rektangle.
public void FillRectangle(Brush brush, Rectangle rectangle)
Parameters
brush
Brush
Pembersih yang menentukan karakteristik pengisian.
rectangle
Rectangle
rektangle untuk mengisi.
Examples
Contoh ini menunjukkan cara membuat gambar WMF dan menggambar beberapa bentuk geometrik menggunakan WmfRecorderGraphics2D.
string dir = "c:\\temp\\";
int imageWidth = 600;
int imageHeight = 400;
// This is the default screen resolution.
int dpi = 96;
Aspose.Imaging.Rectangle frame = new Aspose.Imaging.Rectangle(0, 0, imageWidth, imageHeight);
// Create a WMF image.
Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D graphics =
new Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D(frame, dpi);
// 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, imageWidth, imageHeight);
// 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, imageWidth, imageHeight);
graphics.DrawLine(new Aspose.Imaging.Pen(Aspose.Imaging.Color.DarkGreen, 1), 0, imageHeight, imageWidth, 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, imageWidth, imageHeight),
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.Wmf.WmfImage wmfImage = graphics.EndRecording())
{
wmfImage.Save(dir + "test.output.wmf");
}
Contoh ini menunjukkan bagaimana untuk membuat gambar EMF dan menggambar beberapa bentuk geometrik di atasnya menggunakan 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");
}
GetTransform()
akan mengubah dunia.
public Matrix GetTransform()
Returns
dengan transformasi matriks.
IntersectClip(RectangleF)
Memperbarui wilayah klip grafis ini ke persimpangan wilayah klip saat ini dan struktur Rectangle yang ditentukan.
public void IntersectClip(RectangleF rect)
Parameters
rect
RectangleF
Struktur rektangle untuk berinterseks dengan wilayah klip saat ini.
IntersectClip(Region)
Memperbarui wilayah klip grafis ini ke persimpangan wilayah klip saat ini dan wilayah yang ditentukan.
public void IntersectClip(Region region)
Parameters
region
Region
Wilayah ini terhubung dengan wilayah saat ini.
MultiplyTransform(Matrix)
Meningkatkan transformasi dunia grafis ini dan menentukan matriks.
public void MultiplyTransform(Matrix matrix)
Parameters
matrix
Matrix
Matriks yang memproduksi transformasi dunia.
MultiplyTransform(Matriks dan Matriks)
Meningkatkan transformasi dunia grafis ini dan menentukan matriks dalam perintah yang ditentukan.
public void MultiplyTransform(Matrix matrix, MatrixOrder order)
Parameters
matrix
Matrix
Matriks yang memproduksi transformasi dunia.
order
MatrixOrder
Perintah dari multiplikasi.
ResetClip()
Mengembalikan klip tersebut.
public void ResetClip()
RotateTransform(kapal)
Mengaplikasikan rotasi yang ditentukan pada matriks transformasi grafis ini.
public void RotateTransform(float angle)
Parameters
angle
float
sudut rotasi dalam derajat.
RotateTransform(Fasilitas, PointF, MatrixOrder)
Mengaplikasikan rotasi yang ditentukan pada matriks transformasi grafis ini dalam perintah yang ditentukan.
public void RotateTransform(float angle, PointF center, MatrixOrder order)
Parameters
angle
float
sudut rotasi dalam derajat.
center
PointF
dari pusat rotasi.
order
MatrixOrder
Menentukan apakah rotasi dilampirkan atau dilampirkan pada transformasi matriks.
ScaleTransform(Banjir, Banjir)
Mengaplikasikan operasi skala yang ditentukan pada matriks transformasi grafis ini dengan mempersekutukan matriks transformasi objek.
public void ScaleTransform(float sx, float sy)
Parameters
sx
float
Faktor skala dalam arah x.
sy
float
Faktor skala dalam arah y.
ScaleTransform(Banjir, Banjir dan MatrixOrder)
Mengaplikasikan operasi skala yang ditentukan pada matriks transformasi grafis ini dalam perintah yang ditentukan.
public void ScaleTransform(float sx, float sy, MatrixOrder order)
Parameters
sx
float
Faktor skala dalam arah x.
sy
float
Faktor skala dalam arah y.
order
MatrixOrder
Menentukan apakah operasi penghitungan dilipat atau dilipat ke matriks transformasi.
SetTransform(Matrix)
mengatur transformasi.
public void SetTransform(Matrix transform)
Parameters
transform
Matrix
Matriks transformasi baru.
Examples
Contoh ini menunjukkan cara memuat gambar EMF dari file dan menggambar string teks di atasnya.
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");
}
}
TranslateTransform(Banjir, Banjir)
Mengubah asal-usul sistem koordinat dengan mempersiapkan terjemahan yang ditentukan ke matriks transformasi grafis ini.
public void TranslateTransform(float x, float y)
Parameters
x
float
x koordinat dari terjemahan.
y
float
dan koordinat dari terjemahan.
TranslateTransform(Banjir, Banjir dan MatrixOrder)
Mengubah asal-usul sistem koordinat dengan menerapkan terjemahan yang ditentukan pada matriks transformasi grafis ini dalam perintah yang ditentukan.
public void TranslateTransform(float x, float y, MatrixOrder order)
Parameters
x
float
x koordinat dari terjemahan.
y
float
dan koordinat dari terjemahan.
order
MatrixOrder
Menentukan apakah terjemahan diprediksi atau dilampirkan ke matriks transformasi.