示例#1
0
        static void Main(string[] args)
        {
            // 1. Create conversion options
            WpfDrawingSettings settings = new WpfDrawingSettings();
            settings.IncludeRuntime = true;
            settings.TextAsGeometry = false;

            // 2. Select a file to be converted
            string svgTestFile = "Test.svg";

            // 3. Create a file converter
            ImageSvgConverter converter = new ImageSvgConverter(settings);
            // 4. Perform the conversion to image
            converter.EncoderType = ImageEncoderType.BmpBitmap;
            converter.Convert(svgTestFile);

            converter.EncoderType = ImageEncoderType.GifBitmap;
            converter.Convert(svgTestFile);

            converter.EncoderType = ImageEncoderType.JpegBitmap;
            converter.Convert(svgTestFile);

            converter.EncoderType = ImageEncoderType.PngBitmap;
            converter.Convert(svgTestFile);

            converter.EncoderType = ImageEncoderType.TiffBitmap;
            converter.Convert(svgTestFile);

            converter.EncoderType = ImageEncoderType.WmpBitmap;
            converter.Convert(svgTestFile);
        }
示例#2
0
        static void Main(string[] args)
        {
            // Reference WindowsBase
            // 1. Create conversion options
            WpfDrawingSettings settings = new WpfDrawingSettings();
            settings.IncludeRuntime = true;
            settings.TextAsGeometry = false;

            // 2. Select a file to be converted
            string svgTestFile = @"C:\Users\Administrator\Desktop\svg\chart.svg";
            string imgfilename = @"C:\Users\Administrator\Desktop\svg\chart.jpg";
            // 3. Create a file converter
            ImageSvgConverter converter = new ImageSvgConverter(settings);
            // 4. Perform the conversion to image
            converter.EncoderType = ImageEncoderType.JpegBitmap;
            converter.Convert(svgTestFile, imgfilename);
        }
示例#3
0
        private void ConvertImages(DirectoryInfo source, DirectoryInfo target)
        {
            _errorFile = null;

            var imageConverter = new ImageSvgConverter(this.SaveXaml, this.SaveZaml, this.DrawingSettings);

            imageConverter.Background            = this.Background;
            imageConverter.FallbackOnWriterError = _fallbackOnWriterError;
            imageConverter.EncoderType           = _encoderType;
            imageConverter.Encoder = _bitampEncoder;

            imageConverter.DpiX = _dpiX;
            imageConverter.DpiY = _dpiY;

            string targetDirName = target.ToString();
            string xamlFilePath;

            var fileIterator = Directory.EnumerateFiles(source.FullName, "*.svg*", SearchOption.TopDirectoryOnly);

            foreach (string svgFileName in fileIterator)
            {
                string fileExt = Path.GetExtension(svgFileName);
                if (string.Equals(fileExt, SvgExt, StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(fileExt, CompressedSvgExt, StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        FileAttributes fileAttr = File.GetAttributes(svgFileName);
                        if (!_includeHidden)
                        {
                            if ((fileAttr & FileAttributes.Hidden) == FileAttributes.Hidden)
                            {
                                continue;
                            }
                        }

                        xamlFilePath = Path.Combine(targetDirName, Path.GetFileNameWithoutExtension(svgFileName) + XamlExt);

                        imageConverter.Convert(svgFileName, xamlFilePath);

                        File.SetAttributes(xamlFilePath, fileAttr);
#if NET40
                        // if required to set the security or access control
                        if (_includeSecurity)
                        {
                            File.SetAccessControl(xamlFilePath, File.GetAccessControl(svgFileName));
                        }
#endif
                        _convertedCount++;

                        if (imageConverter.WriterErrorOccurred)
                        {
                            _writerErrorOccurred = true;
                        }
                    }
                    catch
                    {
                        _errorFile = svgFileName;

                        throw;
                    }
                }
            }
        }