Is there a way to display an SVG image (from a URL) in a xaml Image control in a UWP app
e.g.
<Image Source={Binding image_source}>
Where image_source is an absolute path to an image. Where the image is either png or svg format.
My solution works as expected with any common graphics format (jpg, png, gif) but displays nothing when the graphic is svg format.
I've seen loads of articles about converting the svg to something else, but the information comes from a web service that is not mine and use by others I would suspect. changing images on mass to png or something else I doubt would be an option.
In my application the Image is within a listView.
I've seen articles about converters and built in support for svg but none of them seem to work. I have yet to find any article here or anywhere with someone that has a working solution other than manually converting files (not an option)
Any help would be much appreciated.
UWP supports SVG natively and your solution should work. I guess the issue in your case is due to scaling. Make sure your graphics image has not scaled out of boundaries and you only see transparent part of it. You might try testing other SVG files to confirm that and play with size and SVG ViewBox attribute.
Related
I need to render complex svg files in my UWP application, but I haven't found any way to properly render a svg file from a path without using a WebView.
Is there a library which is able to do that? Moreover it would be great if it provides DataBinding.
With complex I mean every valid svg file should be able to render properly. e.g. a base64 encoded image within the svg file
Currently I use a WebView but there are a few caveats:
kinda slow. it takes approximately a second to load. I'd expect at most 500ms (I think that's possible)
I have to know the size of the file in advance
there are sometimes clipping issues
I use it inside a scroll view with the ability to zoom and sometimes something breaks and weird things happen
I have to cover the web view with another view and forward the events to the ScrollView (not very MVVM friendly)
Is there a way to render svg files in UWP
Sure, please refer SvgImageSource document, it could used to render svg image file. You can define a SvgImageSource by using a Uniform Resource Identifier (URI) that references a SVG file.
For example
<Image
Width="24"
Height="24"
Stretch="Fill">
<Image.Source>
<SvgImageSource
UriSource="/Assets/AddComment.svg" />
</Image.Source>
</Image>
And you could also use Win2D library to render SVG file, this related care reply that you could refer to.
I am using System.Windows.Forms.DataVisualization.Charting chart control to render graphs for some data in my c# winforms application. I now need to save those graphs/charts as .svg or any other lossless vector image, so that it can be seemlessly scaled when used in report.pdf.
Any suggestions are welcome.
I have looked into SaveImage(String, ChartImageFormat), where ChartImageFormat is an enum that does not include any vector image formats. Also searched stackoverflow and similar repos for an answer and as far as I see this is actually a duplicate question (Save ms chart control image as svg file using C# SVG rendering library from github), but the guy quit and used oxyplot instead.
chart.AntiAliasing = AntiAliasingStyles.All;
string imageNameAndPath = "TempImages/Image.png";
chart.SaveImage(imageNameAndPath, ChartImageFormat.Png);
In short I would like to do what the above code does but with ChartImageFormat.SVG or similar.
Edit: #TaW It seems now to me that I was not able to formulate the question correctly. To elaborate: Pictured here are two plots;
the violet one is from mentioned win forms, the white one is from oxyplot. Both get saved into files; the first one to emf the second one to svg file. Bit when those files are opened and zoomed in this is what I get:
So now I am not sure from where this quality difference originates, but it is obvious. So I guess my question is: how would it be possible to save a chart in windows forms in a vector format of a similar quality as it is the one from Oxyplot, preferably without actually drawing on screen (somehow drawing directly to a file, so to speak)?
I have a large number of svg files (over 1000) that have keyframe animations included in the CSS. Ultimately I want to be able to display these in an android app.
I looked into using android vectordrawable among other solutions but that will only display the image from path data and wont be feasible to try add animations to every file.
I have have also tried converting to png using http://www.codeplex.com/svg in c#, again the png file does not include the animation.
You can use a Webview to display your svg.
here is a post that can help .svg file as object in HTML
I am in need of converting a base64 encoded svg to a png and then returning it to the client to be rendered.
The idea is that I am drawing an svg on the client using d3.js and I need to convert it to png.
I tried taking the javascript root and writing the svg on the canvas and then converting it toDataUrl but IE has problems with this on all versions so this is not a viable option.
I have searched online a bit and all I could find is Inkscape.
This is not a viable solution for me because of limited access on the server and frankly I don't think it's a good idea to install an entire application for a simple functionality.
Is there any other solution that can take a base 64 encoded svg and return a png that can be displayed in an image?
I found that since I have to support IE 11 I instead went with canvas to blob to PNG using "canvas-toBlob.js" and "FileSaver.js"
$("#save-btn").click(function()
{
$("#myChart").get(0).toBlob(function(blob)
{
saveAs(blob, "chart_1.png");
});
});
https://jsfiddle.net/mfvmoy64/155
I am facing the same issue, however I been able to render the SVG into an image so your users could right click to download the image or right click on the canvas. There is also Canvg which has a library that appears to work with IE, however it is not accurate for complex SVG and so does not meet my needs. Perhaps it will help you.
I have code in my question that will work in IE, just use the IMG or Canvas object, you do not need to call toDataURI.
Checkout Canvg, it might be of help.
Good luck! If you find a better solution, please let me know. :-)
I have swf file's that's contains 2D images (here one of them: http://mapviewer.ru/img/tramvay/depo_d.swf )
I need draw this image (like seen in my browser), to bitmap.
Maybe i need convert this file to image (png, jpg)? No matter how, but it should be done programmatically.
Updated
Have you tried to look at this library ?
There are no embedded images inside the SWF file, only Vector shapes, which means you would need to both parse the SWF and render the data that is inside, so taking a screenshot of it is probably your best option. There are a lot of ways of doing this, but you could simply load the Flash Active-x in your application and take a screenshot. Here's how to load the SWF : Displaying Flash content in a C# WinForms application