Exemplo n.º 1
0
        private void OnWindowLoaded(object sender, RoutedEventArgs e)
        {
            // 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 reader
            StreamSvgConverter converter = new StreamSvgConverter(settings);
            // 4. convert the SVG file
            MemoryStream memStream = new MemoryStream();

            if (converter.Convert(svgTestFile, memStream))
            {
                BitmapImage bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.CacheOption = BitmapCacheOption.OnLoad;
                bitmap.StreamSource = memStream;
                bitmap.EndInit();
                // Set the image source.
                svgImage.Source = bitmap;
            }

            memStream.Close();
        }
    private MemoryStream GetJSImage(Hashtable exportData, bool processPdf)
    {
        MemoryStream exportObjectStream = new MemoryStream();

        //string filename = exportData["filename"].ToString();
        string type = exportData["exportformat"].ToString().ToLower();

        if (processPdf)
        {
            type = "jpg";
        }

        SharpVectors.Renderers.Wpf.WpfDrawingSettings ds = new SharpVectors.Renderers.Wpf.WpfDrawingSettings();

        StreamSvgConverter ssc = new StreamSvgConverter(ds);
        ssc.SaveXaml = false;
        ssc.SaveZaml = false;

        ImageEncoderType encoder = ImageEncoderType.JpegBitmap;

        switch (type)
        {
            case "png":
                encoder = ImageEncoderType.PngBitmap;
                break;
            case "jpeg":
                encoder = ImageEncoderType.JpegBitmap;
                break;
        }

        ssc.EncoderType = encoder;
        ssc.SaveXaml = false;

        if (ssc.Convert(svgData, exportObjectStream))
        {

            if (processPdf)
            {
                FCJSPDFGenerator PDFGEN = new FCJSPDFGenerator(true, exportObjectStream, ssc.Drawing.Bounds.Width.ToString(), ssc.Drawing.Bounds.Height.ToString());
                exportObjectStream = PDFGEN.getBinaryStream(type);
            }
        }

        svgData.Close();
        svgData.Dispose();
        svgStream.Close();
        svgStream.Dispose();

        return exportObjectStream;
    }