Beispiel #1
0
        public static void Run()
        {
            // ExStart:ExportRasterImageToSvg
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages();

            string[] paths = new string[]
            {
                @"C:\test\butterfly.gif",
                @"C:\test\33715-cmyk.jpeg",
                @"C:\test\3.JPG",
                @"C:\test\test.j2k",
                @"C:\test\Rings.png",
                @"C:\test\3layers_maximized_comp.psd",
                @"C:\test\img4.TIF",
                @"C:\test\Lossy5.webp"
            };

            foreach (string path in paths)
            {
                string destPath = path + ".svg";

                using (Image image = Image.Load(path))
                {
                    SvgOptions svgOptions = new SvgOptions();
                    SvgRasterizationOptions svgRasterizationOptions = new SvgRasterizationOptions();
                    svgOptions.VectorRasterizationOptions            = svgRasterizationOptions;
                    svgOptions.VectorRasterizationOptions.PageWidth  = image.Width;
                    svgOptions.VectorRasterizationOptions.PageHeight = image.Height;

                    image.Save(destPath, svgOptions);
                }
            }
            // ExEnd:ExportRasterImageToSvg
        }
        public static void Run()
        {
            Console.WriteLine("Running example DrawVectorImageToRasterImage");

            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages();

            using (MemoryStream drawnImageStream = new MemoryStream())
            {
                // First, rasterize Svg to Png and write the result to a stream.
                using (SvgImage svgImage = (SvgImage)Image.Load(dataDir + "asposenet_220_src02.svg"))
                {
                    SvgRasterizationOptions rasterizationOptions = new SvgRasterizationOptions();
                    rasterizationOptions.PageSize = svgImage.Size;

                    PngOptions saveOptions = new PngOptions();
                    saveOptions.VectorRasterizationOptions = rasterizationOptions;

                    svgImage.Save(drawnImageStream, saveOptions);

                    // Now load a Png image from stream for further drawing.
                    drawnImageStream.Seek(0, System.IO.SeekOrigin.Begin);
                    using (RasterImage imageToDraw = (RasterImage)Image.Load(drawnImageStream))
                    {
                        // Drawing on the existing Svg image.
                        Aspose.Imaging.FileFormats.Svg.Graphics.SvgGraphics2D graphics =
                            new Aspose.Imaging.FileFormats.Svg.Graphics.SvgGraphics2D(svgImage);

                        // Scale down the entire drawn image by 2 times and draw it to the center of the drawing surface.
                        int   width  = imageToDraw.Width / 2;
                        int   height = imageToDraw.Height / 2;
                        Point origin = new Point((svgImage.Width - width) / 2, (svgImage.Height - height) / 2);
                        Size  size   = new Size(width, height);

                        graphics.DrawImage(imageToDraw, origin, size);

                        // Save the result image
                        using (SvgImage resultImage = graphics.EndRecording())
                        {
                            resultImage.Save(dataDir + "asposenet_220_src02.DrawVectorImage.svg");
                        }
                    }
                }
            }

            Console.WriteLine("Finished example DrawVectorImageToRasterImage");
        }
        public static void Run()
        {
            Console.WriteLine("Running example CompressedVectorFormats");
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_SVG();

            using (var image = Image.Load(System.IO.Path.Combine(dataDir, "Sample.svg")))
            {
                VectorRasterizationOptions vectorRasterizationOptions = new SvgRasterizationOptions()
                {
                    PageSize = image.Size
                };
                image.Save(System.IO.Path.Combine(dataDir, "Sample.svgz"), new SvgOptions()
                {
                    VectorRasterizationOptions = vectorRasterizationOptions, Compress = true
                });
            }

            Console.WriteLine("Finished example CompressedVectorFormats");
        }
Beispiel #4
0
        public static void Run()
        {
            Console.WriteLine("Running example SVGToBMPConversion");

            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_SVG();

            using (Image image = Image.Load(dataDir + "test.svg"))
            {
                BmpOptions options = new BmpOptions();
                SvgRasterizationOptions svgOptions = new SvgRasterizationOptions();

                svgOptions.PageWidth  = 100;
                svgOptions.PageHeight = 200;


                options.VectorRasterizationOptions = svgOptions;

                image.Save(dataDir + "test.svg_out.bmp", options);
            }

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