public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Create an instance of Image and load an existing image using (Image image = Image.Load(dataDir + "WaterMark.bmp")) { // Create and initialize an instance of Graphics class Graphics graphics = new Graphics(image); // Creates an instance of Font Font font = new Font("Times New Roman", 16, FontStyle.Bold); // Create an instance of SolidBrush and set its various properties Brushes.SolidBrush brush = new Brushes.SolidBrush(); brush.Color = Color.Black; brush.Opacity = 100; // Draw a String using the SolidBrush object and Font, at specific Point graphics.DrawString("Aspose.Imaging for .Net", font, brush, new PointF(image.Width / 2, image.Height / 2)); // save the image with changes. image.Save(dataDir + "AddWatermarkToImage_out.bmp"); // Display Status. System.Console.WriteLine("Watermark added successfully."); } }
public static void Run() { // WmfRecorderGraphics2D class provides you the frame or canvas to draw shapes on it. Create an instance of WmfRecorderGraphics2D class. The constructor takes in 2 parameters: 1. Instance of Imaging Rectangle class 2. An integer value for inches // ExStart:CreateWMFMetaFileImage // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); FileFormats.Wmf.Graphics.WmfRecorderGraphics2D graphics = new FileFormats.Wmf.Graphics.WmfRecorderGraphics2D(new Aspose.Imaging.Rectangle(0, 0, 100, 100), 96); // Define background color graphics.BackgroundColor = Color.WhiteSmoke; // Init Create an instance of Imaging Pen class and mention its color. Pen pen = new Pen(Color.Blue); // Create an instance of Imaging Brush class and mention its color. Brush brush = new Brushes.SolidBrush(Color.YellowGreen); // Polygon Fill polygon by calling FillPolygon method and passing parameters brush and points. graphics.FillPolygon(brush, new Point[] { new Point(2, 2), new Point(20, 20), new Point(20, 2) }); // Draw a polygon by calling DrawPolygon method and passing parameters pen and points. graphics.DrawPolygon(pen, new Point[] { new Point(2, 2), new Point(20, 20), new Point(20, 2) }); // Ellipse Create an instance of HatchBrush class set different properties. brush = new HatchBrush() { HatchStyle = HatchStyle.Cross, BackgroundColor = Color.White, ForegroundColor = Aspose.Imaging.Color.Silver }; // Fill ellipse by calling FillEllipse method and passing parameters brush and an instance of Imaging Rectangle class. graphics.FillEllipse(brush, new Rectangle(25, 2, 20, 20)); // Draw an ellipse by calling DrawEllipse method and passing parameters pen and an instance of Imaging Rectangle class. graphics.DrawEllipse(pen, new Rectangle(25, 2, 20, 20)); // Arc Define pen style by setting DashStyle value pen.DashStyle = DashStyle.Dot; // Set color of the pen pen.Color = Color.Black; // Draw an Arc by calling DrawArc method and passing parameters pen and an instance of Imaging Rectangle class. graphics.DrawArc(pen, new Rectangle(50, 2, 20, 20), 0, 180); // CubicBezier pen.DashStyle = DashStyle.Solid; pen.Color = Color.Red; // Draw an CubicBezier by calling DrawCubicBezier method and passing parameters pen and points. graphics.DrawCubicBezier(pen, new Point(10, 25), new Point(20, 50), new Point(30, 50), new Aspose.Imaging.Point(40, 25)); // Image Create an Instance of Image class. using (Image image = Image.Load(dataDir + @"WaterMark.bmp")) { // Cast the instance of image class to RasterImage. RasterImage rasterImage = image as RasterImage; if (rasterImage != null) { // Draw an image by calling DrawImage method and passing parameters rasterimage and point. graphics.DrawImage(rasterImage, new Point(50, 50)); } } // Line Draw a line by calling DrawLine method and passing x,y coordinates of 1st point and same for 2nd point along with color infor as Pen. graphics.DrawLine(pen, new Point(2, 98), new Point(2, 50)); // Pie Define settings of the brush object. brush = new SolidBrush(Color.Green); pen.Color = Color.DarkGoldenrod; // Fill pie by calling FillPie method and passing parameters brush and an instance of Imaging Rectangle class. graphics.FillPie(brush, new Rectangle(2, 38, 20, 20), 0, 45); // Draw pie by calling DrawPie method and passing parameters pen and an instance of Imaging Rectangle class. graphics.DrawPie(pen, new Rectangle(2, 38, 20, 20), 0, 45); pen.Color = Color.AliceBlue; // Polyline Draw Polyline by calling DrawPolyline method and passing parameters pen and points. graphics.DrawPolyline(pen, new Point[] { new Point(50, 40), new Point(75, 40), new Point(75, 45), new Point(50, 45) }); // For having Strings Create an instance of Font class. Font font = new Font("Arial", 16); // Draw String by calling DrawString method and passing parameters string to display, color and X & Y coordinates. graphics.DrawString("Aspose", font, Color.Blue, 25, 75); // Call end recording of graphics object and save WMF image by calling Save method. using (FileFormats.Wmf.WmfImage image = graphics.EndRecording()) { image.Save(dataDir + "CreateWMFMetaFileImage.wmf"); } // ExEnd:CreateWMFMetaFileImage }