How do I convert SVG content to ImageSource?
See original GitHub issueIs 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:
- Created 2 years ago
- Comments:9 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry, I deprived you of that! PR are always welcomed, and there are lots of tasks and issues remaining!!!
@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.