question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

How do I convert SVG content to ImageSource?

See original GitHub issue

Is there a way to convert SVG content to ImageSource using this library?

Context: In my project I have a converter which converts one of my models to ImageSource. I have SVG content ready to go, but havenā€™t found a way to convert that into an ImageSource.

Iā€™ve tried the following:

var cnv = new ImageSvgConverter(new WpfDrawingSettings()
{
    IncludeRuntime = true,
    TextAsGeometry = true,
});

var result = cnv.Convert(tempSVGFilePath);

Iā€™m saving SVG content to a temporary file and Iā€™m trying to convert the local file to ImageSource via ImageSvgConverter . But Iā€™m getting an empty exception when executing the last line of code.

Stack trace of that exception is:

   at SharpVectors.Dom.Css.CssColor.ParseColor(String str)
   at SharpVectors.Dom.Css.CssColor..ctor(String str)
   at SharpVectors.Dom.Css.CssPrimitiveRgbValue.OnSetCssText(String cssText)
   at SharpVectors.Dom.Css.CssPrimitiveRgbValue..ctor(String cssText, Boolean readOnly)
   at SharpVectors.Dom.Css.CssPrimitiveValue.Create(Match match, Boolean readOnly)
   at SharpVectors.Dom.Css.CssValue.GetCssValue(String cssText, Boolean readOnly)
   at SharpVectors.Dom.Css.CssStyleDeclaration.GetPropertyCssValue(String propertyName)
   at SharpVectors.Dom.Css.CssStyleDeclaration.GetStylesForElement(CssCollectedStyleDeclaration csd, Int32 specificity)
   at SharpVectors.Dom.Css.CssXmlElement.GetComputedStyle(String pseudoElt)
   at SharpVectors.Dom.Svg.SvgStyleableElement.GetComputedStyle(String pseudoElt)
   at SharpVectors.Dom.Css.CssXmlElement.GetComputedCssValue(String propertyName, String pseudoElt)
   at SharpVectors.Renderers.Wpf.WpfRendering.SetClip(WpfDrawingContext context)
   at SharpVectors.Renderers.Wpf.WpfRendering.BeforeRender(WpfDrawingRenderer renderer)
   at SharpVectors.Renderers.Wpf.WpfSvgRendering.BeforeRender(WpfDrawingRenderer renderer)
   at SharpVectors.Renderers.Wpf.WpfRenderingHelper.RenderElement(ISvgElement svgElement)
   at SharpVectors.Renderers.Wpf.WpfRenderingHelper.Render(ISvgElement svgElement)
   at SharpVectors.Renderers.Wpf.WpfRenderingHelper.Render(ISvgDocument docElement)
   at SharpVectors.Renderers.Wpf.WpfDrawingRenderer.Render(ISvgDocument node)
   at SharpVectors.Converters.ImageSvgConverter.ProcessFile(String fileName, String imageFileName)
   at SharpVectors.Converters.ImageSvgConverter.Convert(String svgFileName, String imageFileName)
   at SharpVectors.Converters.ImageSvgConverter.Convert(String svgFileName)
   at PVScan.Desktop.WPF.Converters.BarcodeImageConverter.Convert(Object value, Type targetType, Object parameter, CultureInfo culture) in C:\Users\mejev\Desktop\Dev\Personal\PVScan\Source\Desktop\Windows\PVScan.Desktop.WPF\Converters\BarcodeImageConverter.cs:line 63

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
paulushubcommented, Jun 9, 2021

I was actually about to make a pull request myself fixing that.

Sorry, I deprived you of that! PR are always welcomed, and there are lots of tasks and issues remaining!!!

1reaction
meJevincommented, Jun 9, 2021

@paulushub I was actually about to make a pull request myself fixing that. Really love this library. Will gladly explore it more and help if I can šŸ‘

About your solution I will try it in the next couple of days. Thank you so much.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I use SVG image format use as WPF image source
You would have to use a vector based image processing application to convert the SVG to XAML. Generally, the XAML obtained from the...
Read more >
How To Convert SVG Code to Image Online
Head over to our SVG Editor; Ā· Upload or paste your SVG code; Ā· Resize, modify and edit your SVG if necessary; Ā·...
Read more >
Using a string of SVG text as an image source
Step two: convert the string to a blob. let blob = new Blob([svg],Ā ...
Read more >
Converting SVG text string to blob for image source
It is simple to compose an SVG image as a string of text, convert the string to a blob, and use the blob...
Read more >
Convert svg image to ImageSource in code behind
I know how to do this in XAML but I was wondering if there is a simple way to do it in code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found