public static void Run() { //ExStart:CroppingByRectangleEMFImage // The path to the documents directory. string dataDir = RunExamples.GetDataDir_MetaFiles(); // Create an instance of Rasterization options EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions(); emfRasterizationOptions.BackgroundColor = Color.WhiteSmoke; // Create an instance of PNG options PdfOptions pdfOptions = new PdfOptions(); pdfOptions.VectorRasterizationOptions = emfRasterizationOptions; Console.WriteLine("Running example CroppingByRectangleEMFImage"); // Load an existing image into an instance of EMF class using (EmfImage image = (EmfImage)Image.Load(dataDir + "Picture1.emf")) { using (FileStream outputStream = new FileStream(dataDir + "CroppingByRectangleEMFImage_out.pdf", FileMode.Create)) { // Create an instance of Rectangle class with desired size and Perform the crop operation on object of Rectangle class and Set height and width and Save the results to disk image.Crop(new Rectangle(30, 50, 100, 150)); pdfOptions.VectorRasterizationOptions.PageWidth = image.Width; pdfOptions.VectorRasterizationOptions.PageHeight = image.Height; image.Save(outputStream, pdfOptions); } } Console.WriteLine("Finished example CroppingByRectangleEMFImage"); //ExEnd:CroppingByRectangleEMFImage }
public static void Run() { // ExStart:CroppingEMFImage // The path to the documents directory. string dataDir = RunExamples.GetDataDir_MetaFiles(); // Create an instance of Rasterization options EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions(); emfRasterizationOptions.BackgroundColor = Color.WhiteSmoke; // Create an instance of PNG options PdfOptions pdfOptions = new PdfOptions(); pdfOptions.VectorRasterizationOptions = emfRasterizationOptions; // Load an existing image into an instance of EMF class using (EmfImage image = (EmfImage)Image.Load(dataDir + "Picture1.emf")) { using (FileStream outputStream = new FileStream(dataDir + "CroppingEMFImage_out.pdf", FileMode.Create)) { // Based on the shift values, apply the cropping on image and Crop method will shift the image bounds toward the center of image image.Crop(30, 40, 50, 60); // Set height and width and Save the results to disk pdfOptions.VectorRasterizationOptions.PageWidth = image.Width; pdfOptions.VectorRasterizationOptions.PageHeight = image.Height; image.Save(outputStream, pdfOptions); } } // ExEnd:CroppingEMFImage }
public static void Run() { Console.WriteLine("Running example DrawRasterImageOnEMF"); // The path to the documents directory. string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages(); // Load the image to be drawn using (RasterImage imageToDraw = (RasterImage)Image.Load(dataDir + "asposenet_220_src01.png")) { // Load the image for drawing on it (drawing surface) using (EmfImage canvasImage = (EmfImage)Image.Load(dataDir + "input.emf")) { EmfRecorderGraphics2D graphics = EmfRecorderGraphics2D.FromEmfImage(canvasImage); // Draw a rectagular part of the raster image within the specified bounds of the vector image (drawing surface). // Note that because the source size is not equal to the destination one, the drawn image is stretched horizontally and vertically. graphics.DrawImage( imageToDraw, new Rectangle(67, 67, canvasImage.Width, canvasImage.Height), new Rectangle(0, 0, imageToDraw.Width, imageToDraw.Height), GraphicsUnit.Pixel); // Save the result image using (EmfImage resultImage = graphics.EndRecording()) { resultImage.Save(dataDir + "input.DrawImage.emf"); } } } Console.WriteLine("Finished example DrawRasterImageOnEMF"); }
public static void Run() { //ExStart:SaveEmfGraphics // The path to the documents directory. string dataDir = RunExamples.GetDataDir_MetaFiles(); EmfRecorderGraphics2D graphics = new EmfRecorderGraphics2D( new Rectangle(0, 0, 5000, 5000), new Size(5000, 5000), new Size(1000, 1000)); { Font font = new Font("Arial", 10, FontStyle.Bold | FontStyle.Underline); graphics.DrawString(font.Name + " " + font.Size + " " + font.Style.ToString(), font, Color.Brown, 10, 10); graphics.DrawString("some text", font, Color.Brown, 10, 30); font = new Font("Arial", 24, FontStyle.Italic | FontStyle.Strikeout); graphics.DrawString(font.Name + " " + font.Size + " " + font.Style.ToString(), font, Color.Brown, 20, 50); graphics.DrawString("some text", font, Color.Brown, 20, 80); using (EmfImage image = graphics.EndRecording()) { var path = dataDir + @"Fonts.emf"; image.Save(path, new EmfOptions()); } } //ExEnd:SaveEmfGraphics }
public static void Run() { Console.WriteLine("Running example CropEMFFile"); // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); using (EmfImage image = Image.Load(dataDir + "test.emf") as EmfImage) { image.Crop(new Rectangle(10, 10, 100, 150)); Console.WriteLine(image.Width); Console.WriteLine(image.Height); image.Save(dataDir + "test.emf_crop.emf"); } Console.WriteLine("Finished example CropEMFFile"); }
public static void Run() { // ExStart:SpecifyFontFolder // The path to the documents directory. string dataDir = RunExamples.GetDataDir_MetaFiles(); // create an instance of Rasterization options EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions(); emfRasterizationOptions.BackgroundColor = Color.WhiteSmoke; // create an instance of PNG options PngOptions pngOptions = new PngOptions(); pngOptions.VectorRasterizationOptions = emfRasterizationOptions; // load an existing EMF image using (EmfImage image = (EmfImage)Image.Load(dataDir + "Picture1.emf")) { image.CacheData(); // set heigh and width pngOptions.VectorRasterizationOptions.PageWidth = 300; pngOptions.VectorRasterizationOptions.PageHeight = 350; // reset font settings FontSettings.Reset(); image.Save(dataDir + "Picture1_default_fonts_out.png", pngOptions); // initialize font list List <string> fonts = new List <string>(FontSettings.GetDefaultFontsFolders()); // add new font path to font list fonts.Add(dataDir + "arialAndTimesAndCourierRegular.xml"); // assign list of font folders to font settings FontSettings.SetFontsFolders(fonts.ToArray(), true); // save the EMF file to PNG image with new font image.Save(dataDir + "Picture1_with_my_fonts_out.png", pngOptions); } }
public static void Run() { // ExStart:CreateEMFMetaFileImage // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // EmfRecorderGraphics2D class provides you the frame or canvas to draw shapes on it. EmfRecorderGraphics2D graphics = new EmfRecorderGraphics2D(new Rectangle(0, 0, 1000, 1000), new Size(1000, 1000), new Size(100, 100)); { // Create an instance of Imaging Pen class and mention its color. Pen pen = new Pen(Color.Bisque); // 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, 1, 1, 50, 50); // Reset the Pen color Specify the end style of the line. pen = new Pen(Color.BlueViolet, 3); pen.EndCap = LineCap.Round; // 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 and end style of line. graphics.DrawLine(pen, 15, 5, 50, 60); // Specify the end style of the line. pen.EndCap = LineCap.Square; graphics.DrawLine(pen, 5, 10, 50, 10); pen.EndCap = LineCap.Flat; // Draw a line by calling DrawLine method and passing parameters. graphics.DrawLine(pen, new Point(5, 20), new Point(50, 20)); // Create an instance of HatchBrush class to define rectanglurar brush with with different settings. HatchBrush hatchBrush = new HatchBrush { BackgroundColor = Color.AliceBlue, ForegroundColor = Color.Red, HatchStyle = HatchStyle.Cross }; // Draw a line by calling DrawLine method and passing parameters. pen = new Pen(hatchBrush, 7); graphics.DrawRectangle(pen, 50, 50, 20, 30); // Draw a line by calling DrawLine method and passing parameters with different mode. graphics.BackgroundMode = EmfBackgroundMode.OPAQUE; graphics.DrawLine(pen, 80, 50, 80, 80); // Draw a polygon by calling DrawPolygon method and passing parameters with line join setting/style. pen = new Pen(new SolidBrush(Color.Aqua), 3); pen.LineJoin = LineJoin.MiterClipped; graphics.DrawPolygon(pen, new[] { new Point(10, 20), new Point(12, 45), new Point(22, 48), new Point(48, 36), new Point(30, 55) }); // Draw a rectangle by calling DrawRectangle method. pen.LineJoin = LineJoin.Bevel; graphics.DrawRectangle(pen, 50, 10, 10, 5); pen.LineJoin = LineJoin.Round; graphics.DrawRectangle(pen, 65, 10, 10, 5); pen.LineJoin = LineJoin.Miter; graphics.DrawRectangle(pen, 80, 10, 10, 5); // Call EndRecording method to produce the final shape. EndRecording method will return the final shape as EmfImage. So create an instance of EmfImage class and initialize it with EmfImage returned by EndRecording method. using (EmfImage image = graphics.EndRecording()) { // Create an instance of PdfOptions class. PdfOptions options = new PdfOptions(); // Create an instance of EmfRasterizationOptions class and define different settings. EmfRasterizationOptions rasterizationOptions = new EmfRasterizationOptions(); rasterizationOptions.PageSize = image.Size; options.VectorRasterizationOptions = rasterizationOptions; string outPath = dataDir + "CreateEMFMetaFileImage_out.pdf"; image.Save(outPath, options); } } // ExEnd:CreateEMFMetaFileImage }