public static void Run()
        {
            Console.WriteLine("Running example 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
                WmfRasterizationOptions emfRasterization = new WmfRasterizationOptions
                {
                    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);
            }

            Console.WriteLine("Finished example ConvertWMFToWebp");
        }
Beispiel #2
0
        public static void Run()
        {
            Console.WriteLine("Running example 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
                WmfRasterizationOptions emfRasterizationOptions = new WmfRasterizationOptions();
                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);
            }

            Console.WriteLine("Finished example ConvertWMFToPDF");
        }
Beispiel #3
0
        public static void Run()
        {
            Console.WriteLine("Running example ConvertWMFToPNG");
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();

            string inputFileName     = dataDir + "thistlegirl_wmfsample.wmf";
            string outputFileNamePng = dataDir + "thistlegirl_wmfsample.png";


            using (Image image = Image.Load(inputFileName))
            {
                WmfRasterizationOptions rasterizationOptions = new WmfRasterizationOptions();
                rasterizationOptions.BackgroundColor = Color.WhiteSmoke;
                rasterizationOptions.PageWidth       = image.Width;
                rasterizationOptions.PageHeight      = image.Height;

                image.Save(outputFileNamePng, new PngOptions()
                {
                    VectorRasterizationOptions = rasterizationOptions
                });
            }

            Console.WriteLine("Finished example ConvertWMFToPNG");
        }
        public static void Run()
        {
            Console.WriteLine("Running example 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
                WmfRasterizationOptions emfRasterization = new WmfRasterizationOptions
                {
                    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
            }

            Console.WriteLine("Finished example ResizeWMFFile");
        }
        public static void Run()
        {
            Console.WriteLine("Running example 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.
                WmfRasterizationOptions options = new WmfRasterizationOptions();
                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
                });
            }

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