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
        }      
예제 #2
0
        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()
        {
            // 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;

            // 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);
                }
            }
            // ExEnd:CroppingByRectangleEMFImage
        }
예제 #4
0
        static void Main(string[] args)
        {
            //[C# Code Sample]
            // create an instance of Rasterization options
            EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();

            emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke;
            // create an instance of PNG options
            PdfOptions pdfOptions = new PdfOptions();

            pdfOptions.VectorRasterizationOptions = emfRasterizationOptions;
            //Declare variables to store file paths for input and output images
            string filePath = @"E:\armstalker.emf";
            string outPath  = filePath + ".pdf";

            //Load an existing image into an instance of EMF class
            using (Aspose.Imaging.FileFormats.Emf.EmfImage image = (Aspose.Imaging.FileFormats.Emf.EmfImage)Aspose.Imaging.Image.Load(filePath))
            {
                using (FileStream outputStream = new FileStream(outPath, FileMode.Create))
                {
                    //Create an instance of Rectangle class with desired size
                    //Perform the crop operation on object of Rectangle class
                    image.Crop(new Aspose.Imaging.Rectangle(0, 4100, 10000, 1500));
                    // Set height and width
                    pdfOptions.VectorRasterizationOptions.PageWidth  = image.Width;
                    pdfOptions.VectorRasterizationOptions.PageHeight = image.Height;
                    //Save the results to disk
                    image.Save(outputStream, pdfOptions);
                }
            }
        }
        public static void Run()
        {
            // ExStart:ExportMetaFileToRasterFormats
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_MetaFiles();
            string outputfile = dataDir + "file_out";
         
            // Create EmfRasterizationOption class instance and set properties
            EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
            emfRasterizationOptions.BackgroundColor = Color.PapayaWhip;
            emfRasterizationOptions.PageWidth = 300;
            emfRasterizationOptions.PageHeight = 300;

            // Load an existing EMF file as iamge and convert it to EmfImage class object
            using (var image = (EmfImage)Image.Load(dataDir + "Picture1.emf"))
            {
                if (!image.Header.EmfHeader.Valid)
                {
                    throw new ImageLoadException(string.Format("The file {0} is not valid", dataDir + "Picture1.emf"));
                }

                // Convert EMF to BMP, GIF, JPEG, J2K, PNG, PSD, TIFF and WebP
                image.Save(outputfile + ".bmp", new BmpOptions { VectorRasterizationOptions = emfRasterizationOptions });
                image.Save(outputfile + ".gif", new GifOptions { VectorRasterizationOptions = emfRasterizationOptions });
                image.Save(outputfile + ".jpeg", new JpegOptions { VectorRasterizationOptions = emfRasterizationOptions });
                image.Save(outputfile + ".j2k", new Jpeg2000Options { VectorRasterizationOptions = emfRasterizationOptions });
                image.Save(outputfile + ".png", new PngOptions { VectorRasterizationOptions = emfRasterizationOptions });
                image.Save(outputfile + ".psd", new PsdOptions { VectorRasterizationOptions = emfRasterizationOptions });
                image.Save(outputfile + ".tiff", new TiffOptions(TiffExpectedFormat.TiffLzwRgb) { VectorRasterizationOptions = emfRasterizationOptions });
                image.Save(outputfile + ".webp", new WebPOptions { VectorRasterizationOptions = emfRasterizationOptions });
            }
            // ExEnd:ExportMetaFileToRasterFormats
        }       
예제 #6
0
        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:ConvertWMFToWebp
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();

            // Load an existing WMF image
            using (Image image = Image.Load(dataDir + "input.wmf"))
            {
                // Calculate new Webp image height
                double k = (image.Width * 1.00) / image.Height;

                // Create an instance of EmfRasterizationOptions class and set different properties
                EmfRasterizationOptions emfRasterization = new EmfRasterizationOptions
                {
                    BackgroundColor = Color.WhiteSmoke,
                    PageWidth = 400,
                    PageHeight = (int)Math.Round(400 / k),
                    BorderX = 5,
                    BorderY = 10
                };

                // Create an instance of WebPOptions class and provide rasterization option
                ImageOptionsBase imageOptions = new WebPOptions();
                imageOptions.VectorRasterizationOptions = emfRasterization;

                // Call the save method, provide output path and WebPOptions to convert the WMF file to Webp and save the output
                image.Save(dataDir + "ConvertWMFToWebp_out.webp", imageOptions);
            }
            // ExEnd:ConvertWMFToWebp
        }
        public static void Run()
        {
            // ExStart:ConvertWMFToPNG
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();

            // Load an existing WMF image
            using (Image image = Image.Load(dataDir + "input.wmf"))
            {
                // Calculate new Webp image height
                double k = (image.Width * 1.00) / image.Height;

                // Create an instance of EmfRasterizationOptions class and set different properties
                EmfRasterizationOptions emfRasterization = new EmfRasterizationOptions
                {
                    BackgroundColor = Color.WhiteSmoke,
                    PageWidth       = 400,
                    PageHeight      = (int)Math.Round(400 / k),
                    BorderX         = 5,
                    BorderY         = 10
                };

                // Create an instance of PngOptions class and provide rasterization option
                ImageOptionsBase imageOptions = new PngOptions();
                imageOptions.VectorRasterizationOptions = emfRasterization;

                // Call the save method, provide output path and PngOptions to convert the WMF file to PNG and save the output
                image.Save(dataDir + "ConvertWMFToPNG_out.png", imageOptions);
            }
            // ExEnd:ConvertWMFToPNG
        }
예제 #9
0
        public static void Run()
        {
            // ExStart:ExportTextAsShape
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();

            using (Image image = Image.Load(dataDir + "Picture1.emf"))
            {
                EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
                emfRasterizationOptions.BackgroundColor = Color.White;
                emfRasterizationOptions.PageWidth       = image.Width;
                emfRasterizationOptions.PageHeight      = image.Height;
                image.Save(dataDir + "TextAsShapes_out.svg", new SvgOptions
                {
                    VectorRasterizationOptions = emfRasterizationOptions,
                    TextAsShapes = true
                });

                image.Save(dataDir + "TextAsShapesFalse_out.svg", new SvgOptions
                {
                    VectorRasterizationOptions = emfRasterizationOptions,
                    TextAsShapes = false
                });
            }
            // ExEnd:ExportTextAsShape
        }
        public static void Run()
        {
            // ExStart:ResizeWMFFile
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();

            // Load an existing WMF image
            using (Image image = Image.Load(dataDir + "input.wmf"))
            {
                // Call the resize method of Image class and width,height values and Calculate new PNG image height
                image.Resize(100, 100);
                double k = (image.Width * 1.00) / image.Height;

                // Create an instance of EmfRasterizationOptions class and set different properties
                EmfRasterizationOptions emfRasterization = new EmfRasterizationOptions
                {
                    BackgroundColor = Color.WhiteSmoke,
                    PageWidth = 100,
                    PageHeight = (int)Math.Round(100 / k),
                    BorderX = 5,
                    BorderY = 10
                };

                // Create an instance of PngOptions class and provide rasterization option
                ImageOptionsBase imageOptions = new PngOptions();
                imageOptions.VectorRasterizationOptions = emfRasterization;

                // Call the save method, provide output path and PngOptions to convert the WMF file to PNG and save the output
                image.Save(dataDir + "CreateEMFMetaFileImage_out.png", imageOptions);
                // ExStart:ResizeWMFFile
            }
        }
        public static void Run()
        {
            // ExStart:ConvertEMFToPDF
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_MetaFiles();

            string[] filePaths = {
                "Picture1.emf"
            };

            foreach (string filePath in filePaths)
            {
                string outPath = dataDir + filePath + "_out.pdf";
                using (var image = (EmfImage)Image.Load(dataDir + filePath))
                using (FileStream outputStream = new FileStream(outPath, FileMode.Create))
                {
                    if (!image.Header.EmfHeader.Valid)
                    {
                        throw new ImageLoadException(string.Format("The file {0} is not valid", outPath));
                    }

                    EmfRasterizationOptions emfRasterization = new EmfRasterizationOptions();
                    emfRasterization.PageWidth = image.Width;
                    emfRasterization.PageHeight = image.Height;
                    emfRasterization.BackgroundColor = Color.WhiteSmoke;
                    PdfOptions pdfOptions = new PdfOptions();
                    pdfOptions.VectorRasterizationOptions = emfRasterization;
                    image.Save(outputStream, pdfOptions);
                }
            }
            // ExEnd:ConvertEMFToPDF
        }
예제 #12
0
        public static void Run()
        {
            // ExStart:ConvertEMFToPDF
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_MetaFiles();

            string[] filePaths =
            {
                "Picture1.emf"
            };

            foreach (string filePath in filePaths)
            {
                string outPath = dataDir + filePath + "_out.pdf";
                using (var image = (EmfImage)Image.Load(dataDir + filePath))
                    using (FileStream outputStream = new FileStream(outPath, FileMode.Create))
                    {
                        if (!image.Header.EmfHeader.Valid)
                        {
                            throw new ImageLoadException(string.Format("The file {0} is not valid", outPath));
                        }

                        EmfRasterizationOptions emfRasterization = new EmfRasterizationOptions();
                        emfRasterization.PageWidth       = image.Width;
                        emfRasterization.PageHeight      = image.Height;
                        emfRasterization.BackgroundColor = Color.WhiteSmoke;
                        PdfOptions pdfOptions = new PdfOptions();
                        pdfOptions.VectorRasterizationOptions = emfRasterization;
                        image.Save(outputStream, pdfOptions);
                    }
            }
            // ExEnd:ConvertEMFToPDF
        }
        public static void Run()
        {
            // ExStart:ExportTextAsShape
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();
            using (Image image = Image.Load(dataDir + "Picture1.emf"))
            {
                EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
                emfRasterizationOptions.BackgroundColor = Color.White;
                emfRasterizationOptions.PageWidth = image.Width;
                emfRasterizationOptions.PageHeight = image.Height;
                image.Save(dataDir + "TextAsShapes_out.svg", new SvgOptions
                {
                    VectorRasterizationOptions = emfRasterizationOptions,
                    TextAsShapes = true
                });

                image.Save(dataDir + "TextAsShapesFalse_out.svg", new SvgOptions
                {
                    VectorRasterizationOptions = emfRasterizationOptions,
                    TextAsShapes = false
                });
            }
            // ExEnd:ExportTextAsShape
        }
        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 height and width, Reset font settings
                pngOptions.VectorRasterizationOptions.PageWidth = 300;
                pngOptions.VectorRasterizationOptions.PageHeight = 350;
                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 and Assign list of font folders to font settings and Save the EMF file to PNG image with new font
                fonts.Add(dataDir + "arialAndTimesAndCourierRegular.xml");
                FontSettings.SetFontsFolders(fonts.ToArray(), true);
                image.Save(dataDir + "Picture1_with_my_fonts_out.png", pngOptions);
            }
            // ExEnd:SpecifyFontFolder
        }     
예제 #15
0
        private void Save(bool useEmbedded, string fileName, string[] expectedImages)
        {
            if (!Directory.Exists(OutFolder))
            {
                Directory.CreateDirectory(OutFolder);
            }

            string storeType   = useEmbedded ? "Embedded" : "Stream";
            string inputFile   = Path.Combine(SourceFolder, fileName);
            string outFileName = Path.GetFileNameWithoutExtension(fileName) + "_" + storeType + ".svg";
            string outputFile  = Path.Combine(OutFolder, outFileName);
            string imageFolder = string.Empty;

            using (Image image = Image.Load(inputFile))
            {
                EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
                emfRasterizationOptions.BackgroundColor = Color.White;
                emfRasterizationOptions.PageWidth       = image.Width;
                emfRasterizationOptions.PageHeight      = image.Height;
                string testingFileName = Path.GetFileNameWithoutExtension(inputFile);
                imageFolder = Path.Combine(ImageFolder, testingFileName);
                image.Save(outputFile,
                           new SvgOptions
                {
                    VectorRasterizationOptions = emfRasterizationOptions,
                    Callback =
                        new SvgCallbackImageTest(useEmbedded, imageFolder)
                    {
                        Link = ImageFolderName + "/" + testingFileName
                    }
                });
            }

            if (!useEmbedded)
            {
                string[] files = Directory.GetFiles(imageFolder);
                if (files.Length != expectedImages.Length)
                {
                    throw new Exception(string.Format("Expected count font files = {0}, Current count image files = {1}", expectedImages.Length, files.Length));
                }

                for (int i = 0; i < files.Length; i++)
                {
                    string file = Path.GetFileName(files[i]);
                    if (string.IsNullOrEmpty(file))
                    {
                        throw new Exception(string.Format("Expected file name: '{0}', current is empty", expectedImages[i]));
                    }

                    if (file.ToLower() != expectedImages[i])
                    {
                        throw new Exception(string.Format("Expected file name: '{0}', current: '{1}'", expectedImages[i], file.ToLower()));
                    }
                }
            }
        }
        public static void Run()
        {
            // ExStart:ExportMetaFileToRasterFormats
            // The path to the documents directory.
            string dataDir    = RunExamples.GetDataDir_MetaFiles();
            string outputfile = dataDir + "file_out";

            // Create EmfRasterizationOption class instance and set properties
            EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();

            emfRasterizationOptions.BackgroundColor = Color.PapayaWhip;
            emfRasterizationOptions.PageWidth       = 300;
            emfRasterizationOptions.PageHeight      = 300;

            // Load an existing EMF file as iamge and convert it to EmfImage class object
            using (var image = (EmfImage)Image.Load(dataDir + "Picture1.emf"))
            {
                if (!image.Header.EmfHeader.Valid)
                {
                    throw new ImageLoadException(string.Format("The file {0} is not valid", dataDir + "Picture1.emf"));
                }

                // Convert EMF to BMP, GIF, JPEG, J2K, PNG, PSD, TIFF and WebP
                image.Save(outputfile + ".bmp", new BmpOptions {
                    VectorRasterizationOptions = emfRasterizationOptions
                });
                image.Save(outputfile + ".gif", new GifOptions {
                    VectorRasterizationOptions = emfRasterizationOptions
                });
                image.Save(outputfile + ".jpeg", new JpegOptions {
                    VectorRasterizationOptions = emfRasterizationOptions
                });
                image.Save(outputfile + ".j2k", new Jpeg2000Options {
                    VectorRasterizationOptions = emfRasterizationOptions
                });
                image.Save(outputfile + ".png", new PngOptions {
                    VectorRasterizationOptions = emfRasterizationOptions
                });
                image.Save(outputfile + ".psd", new PsdOptions {
                    VectorRasterizationOptions = emfRasterizationOptions
                });
                image.Save(outputfile + ".tiff", new TiffOptions(TiffExpectedFormat.TiffLzwRgb)
                {
                    VectorRasterizationOptions = emfRasterizationOptions
                });
                image.Save(outputfile + ".webp", new WebPOptions {
                    VectorRasterizationOptions = emfRasterizationOptions
                });
            }
            // ExEnd:ExportMetaFileToRasterFormats
        }
        public static void Run()
        {
            // ExStart:ConvertWMFMetaFileToSVG
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();

            // Create an instance of Image class by loading an existing .
            using (Image image = Image.Load(dataDir + "input.wmf"))
            {
                // Create an instance of EmfRasterizationOptions class.
                EmfRasterizationOptions options = new EmfRasterizationOptions();
                options.PageWidth = image.Width;
                options.PageHeight = image.Height;

                // Call save method to convert WMF to SVG format by passing output file name and SvgOptions class instance.
                image.Save(dataDir + "ConvertWMFMetaFileToSVG_out.svg", new SvgOptions { VectorRasterizationOptions = options });
            }
            // ExEnd:ConvertWMFMetaFileToSVG
        }
    private void Save(bool useEmbedded, string fileName, int expectedCountFonts)
    {
        if (!Directory.Exists(OutFolder))
        {
            Directory.CreateDirectory(OutFolder);
        }
        string fontStoreType = useEmbedded ? "Embedded" : "Stream";
        string inputFile     = Path.Combine(SourceFolder, fileName);
        string outFileName   = Path.GetFileNameWithoutExtension(fileName) + "_" + fontStoreType + ".svg";
        string outputFile    = Path.Combine(OutFolder, outFileName);
        string fontFolder    = string.Empty;

        using (Image image = Image.Load(inputFile))
        {
            EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
            emfRasterizationOptions.BackgroundColor = Color.White;
            emfRasterizationOptions.PageWidth       = image.Width;
            emfRasterizationOptions.PageHeight      = image.Height;
            string testingFileName = Path.GetFileNameWithoutExtension(inputFile);
            fontFolder = Path.Combine(FontFolder, testingFileName);
            image.Save(outputFile,
                       new SvgOptions
            {
                VectorRasterizationOptions = emfRasterizationOptions,
                Callback =
                    new SvgCallbackFontTest(useEmbedded, fontFolder)
                {
                    Link = FontFolderName + "/" + testingFileName
                }
            });
        }

        if (!useEmbedded)
        {
            string[] files = Directory.GetFiles(fontFolder);
            if (files.Length != expectedCountFonts)
            {
                throw new Exception(string.Format(
                                        "Expected count font files = {0}, Current count font files = {1}", expectedCountFonts,
                                        files.Length));
            }
        }
    }
        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);
            }
        }
예제 #20
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();

            // Load an existing EMF file as Image.
            using (Image image = Image.Load(dataDir + "Picture1.emf"))
            {
                // Call the Save method of Image class & Pass instance of WmfOptions class to Save method.

                EmfRasterizationOptions emfRasterization = new EmfRasterizationOptions();
                emfRasterization.BackgroundColor = Color.Yellow;
                emfRasterization.PageWidth       = 100;
                emfRasterization.PageHeight      = 100;
                emfRasterization.BorderX         = 5;
                emfRasterization.BorderY         = 10;

                image.Save(dataDir + "ConvertEMFToWMF_out.wmf", emfRasterization);
            }
        }
        public static void Run()
        {
            // ExStart:ConvertWMFMetaFileToSVG
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();

            // Create an instance of Image class by loading an existing .
            using (Image image = Image.Load(dataDir + "input.wmf"))
            {
                // Create an instance of EmfRasterizationOptions class.
                EmfRasterizationOptions options = new EmfRasterizationOptions();
                options.PageWidth  = image.Width;
                options.PageHeight = image.Height;

                // Call save method to convert WMF to SVG format by passing output file name and SvgOptions class instance.
                image.Save(dataDir + "ConvertWMFMetaFileToSVG_out.svg", new SvgOptions {
                    VectorRasterizationOptions = options
                });
            }
            // ExEnd:ConvertWMFMetaFileToSVG
        }
        public static void Run()
        {
            // ExStart:ConvertWMFToPDF
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();

            // Load an existing WMF image
            using (Image image = Image.Load(dataDir + "input.wmf"))
            {
                // Create an instance of EmfRasterizationOptions class and set different properties
                EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
                emfRasterizationOptions.BackgroundColor = Color.WhiteSmoke;
                emfRasterizationOptions.PageWidth = image.Width;
                emfRasterizationOptions.PageHeight = image.Height;

                // Create an instance of PdfOptions class and provide rasterization option
                PdfOptions pdfOptions = new PdfOptions();
                pdfOptions.VectorRasterizationOptions = emfRasterizationOptions;

                // Call the save method, provide output path and PdfOptions to convert the WMF file to PDF and save the output
                image.Save(dataDir + "ConvertWMFToPDF_out.pdf", pdfOptions);
            }
            // ExEnd:ConvertWMFToPDF
        }
예제 #23
0
        public static void Run()
        {
            // ExStart:ConvertWMFToPDF
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();

            // Load an existing WMF image
            using (Image image = Image.Load(dataDir + "input.wmf"))
            {
                // Create an instance of EmfRasterizationOptions class and set different properties
                EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
                emfRasterizationOptions.BackgroundColor = Color.WhiteSmoke;
                emfRasterizationOptions.PageWidth       = image.Width;
                emfRasterizationOptions.PageHeight      = image.Height;

                // Create an instance of PdfOptions class and provide rasterization option
                PdfOptions pdfOptions = new PdfOptions();
                pdfOptions.VectorRasterizationOptions = emfRasterizationOptions;

                // Call the save method, provide output path and PdfOptions to convert the WMF file to PDF and save the output
                image.Save(dataDir + "ConvertWMFToPDF_out.pdf", pdfOptions);
            }
            // ExEnd:ConvertWMFToPDF
        }
        public static void Run()
        {
            Console.WriteLine("Running example SupportOfSmoothingMode");
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();


            string[] files = new string[]
            {
                "SmoothingTest.cdr", "SmoothingTest.cmx", "SmoothingTest.emf", "SmoothingTest.wmf",
                "SmoothingTest.odg", "SmoothingTest.svg"
            };
            SmoothingMode[] smoothingModes = new SmoothingMode[] { SmoothingMode.AntiAlias, SmoothingMode.None };
            foreach (string fileName in files)
            {
                using (Image image = Image.Load(dataDir + fileName))
                {
                    VectorRasterizationOptions vectorRasterizationOptions;
                    if (image is CdrImage)
                    {
                        vectorRasterizationOptions = new CdrRasterizationOptions();
                    }
                    else if (image is CmxImage)
                    {
                        vectorRasterizationOptions = new CmxRasterizationOptions();
                    }
                    else if (image is EmfImage)
                    {
                        vectorRasterizationOptions = new EmfRasterizationOptions();
                    }
                    else if (image is WmfImage)
                    {
                        vectorRasterizationOptions = new WmfRasterizationOptions();
                    }
                    else if (image is OdgImage)
                    {
                        vectorRasterizationOptions = new OdgRasterizationOptions();
                    }
                    else if (image is SvgImage)
                    {
                        vectorRasterizationOptions = new SvgRasterizationOptions();
                    }
                    else
                    {
                        throw new Exception("This is image is not supported in this example");
                    }

                    vectorRasterizationOptions.PageSize = image.Size;
                    foreach (SmoothingMode smoothingMode in smoothingModes)
                    {
                        string outputFileName = dataDir + "image_" + smoothingMode + "_" + fileName + ".png";
                        vectorRasterizationOptions.SmoothingMode = smoothingMode;
                        image.Save(
                            outputFileName,
                            new PngOptions()
                        {
                            VectorRasterizationOptions = vectorRasterizationOptions
                        });
                    }
                }
            }

            Console.WriteLine("Finished example SupportOfSmoothingMode");
        }
        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
        }
        public static void Run()
        {
            Console.WriteLine("Running example SupportOfTextRenderingHint");
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();

            string[] files = new string[] {
                "TextHintTest.cdr",
                "TextHintTest.cmx",
                "TextHintTest.emf",
                "TextHintTest.wmf",
                "TextHintTest.odg",
                "TextHintTest.svg"
            };
            TextRenderingHint[] textRenderingHints = new TextRenderingHint[] {
                TextRenderingHint.AntiAlias, TextRenderingHint.AntiAliasGridFit,
                TextRenderingHint.ClearTypeGridFit, TextRenderingHint.SingleBitPerPixel, TextRenderingHint.SingleBitPerPixelGridFit
            };
            foreach (string fileName in files)
            {
                using (Image image = Image.Load(dataDir + fileName))
                {
                    VectorRasterizationOptions vectorRasterizationOptions;
                    if (image is CdrImage)
                    {
                        vectorRasterizationOptions = new CdrRasterizationOptions();
                    }
                    else if (image is CmxImage)
                    {
                        vectorRasterizationOptions = new CmxRasterizationOptions();
                    }
                    else if (image is EmfImage)
                    {
                        vectorRasterizationOptions = new EmfRasterizationOptions();
                    }
                    else if (image is WmfImage)
                    {
                        vectorRasterizationOptions = new WmfRasterizationOptions();
                    }
                    else if (image is OdgImage)
                    {
                        vectorRasterizationOptions = new OdgRasterizationOptions();
                    }
                    else if (image is SvgImage)
                    {
                        vectorRasterizationOptions = new SvgRasterizationOptions();
                    }
                    else
                    {
                        throw new Exception("This is image is not supported in this example");
                    }
                    vectorRasterizationOptions.PageSize = image.Size;
                    foreach (TextRenderingHint textRenderingHint in textRenderingHints)
                    {
                        string outputFileName = dataDir + "image_" + textRenderingHint + "_" + fileName + ".png";
                        vectorRasterizationOptions.TextRenderingHint = textRenderingHint;
                        image.Save(outputFileName, new PngOptions()
                        {
                            VectorRasterizationOptions = vectorRasterizationOptions
                        });
                    }
                }
            }

            Console.WriteLine("Finished example SupportOfTextRenderingHint");
        }
        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
        }