public static DrawingImage ReadSvgImage(string pathName)
        {
            string       svgPath = pathName;
            DrawingImage image   = new DrawingImage();

            SharpVectors.Renderers.Wpf.WpfDrawingSettings settings = new SharpVectors.Renderers.Wpf.WpfDrawingSettings();
            settings.IncludeRuntime = true;
            SharpVectors.Converters.FileSvgReader reader = new SharpVectors.Converters.FileSvgReader(settings);
            DrawingGroup group;
            FileStream   stream = null;

            try
            {
                stream        = new FileStream(svgPath, FileMode.Open, FileAccess.Read);
                group         = reader.Read(stream);
                image.Drawing = group;
            }
            catch (Exception e)
            {
                //MessageBox.Show(e.Message);
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }
            return(image);
        }
Exemple #2
0
 /// <summary>
 /// Background task work method.
 /// </summary>
 private void DoPrepareSvg(object sender, DoWorkEventArgs e)
 {
     // Lock to allow only one of these operations at a time.
     lock (_updateLock)
     {
         KanjiDao dao = new KanjiDao();
         // Get the kanji strokes.
         KanjiStrokes strokes = dao.GetKanjiStrokes(_kanjiEntity.DbKanji.ID);
         if (strokes != null && strokes.FramesSvg.Length > 0)
         {
             // If the strokes was successfuly retrieved, we have to read the compressed SVG contained inside.
             SharpVectors.Renderers.Wpf.WpfDrawingSettings settings = new SharpVectors.Renderers.Wpf.WpfDrawingSettings();
             using (FileSvgReader r = new FileSvgReader(settings))
             {
                 // Unzip the stream and remove instances of "px" that are problematic for SharpVectors.
                 string svgString = StringCompressionHelper.Unzip(strokes.FramesSvg);
                 svgString    = svgString.Replace("px", string.Empty);
                 StrokesCount = Regex.Matches(svgString, "<circle").Count;
                 using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(svgString)))
                 {
                     // Then read the stream to a DrawingGroup.
                     // We are forced to do this operation on the UI thread because DrawingGroups must
                     // be always manipulated by the same thread.
                     DispatcherHelper.Invoke(() =>
                     {
                         StrokesDrawingGroup = r.Read(stream);
                         SetCurrentStroke(1);
                     });
                 }
             }
         }
     }
 }
 /// <summary>
 /// Background task work method.
 /// </summary>
 private void DoPrepareSvg(object sender, DoWorkEventArgs e)
 {
     // Lock to allow only one of these operations at a time.
     lock (_updateLock)
     {
         KanjiDao dao = new KanjiDao();
         // Get the kanji strokes.
         KanjiStrokes strokes = dao.GetKanjiStrokes(_kanjiEntity.DbKanji.ID);
         if (strokes != null && strokes.FramesSvg.Length > 0)
         {
             // If the strokes was successfuly retrieved, we have to read the compressed SVG contained inside.
             SharpVectors.Renderers.Wpf.WpfDrawingSettings settings = new SharpVectors.Renderers.Wpf.WpfDrawingSettings();
             using (FileSvgReader r = new FileSvgReader(settings))
             {
                 // Unzip the stream and remove instances of "px" that are problematic for SharpVectors.
                 string svgString = StringCompressionHelper.Unzip(strokes.FramesSvg);
                 svgString = svgString.Replace("px", string.Empty);
                 StrokesCount = Regex.Matches(svgString, "<circle").Count;
                 using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(svgString)))
                 {
                     // Then read the stream to a DrawingGroup.
                     // We are forced to do this operation on the UI thread because DrawingGroups must
                     // be always manipulated by the same thread.
                     DispatcherHelper.Invoke(() => 
                         {
                             StrokesDrawingGroup = r.Read(stream);
                             SetCurrentStroke(1);
                         });
                 }
             }
         }
     }
 }