Click here to Skip to main content
15,885,824 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my application I am using svg files like background of my tabs in my tabContainer. User should be able dynamically add, delete or change background of the tab and save it to database. A field in database for an image is byte[](like for usual images).Can anyboby provide example or link of converting svg files to byte[]? Or may be there is better way of saving svg files to database?
Thank in advance.
Posted
Updated 30-Oct-13 4:50am
v2
Comments
Sergey Alexandrovich Kryukov 30-Oct-13 11:47am    
I wonder why?
—SA

Use System.Text.Encoding.

C#
var svgString = "data should be your svg file";
var bytes = Encoding.UTF8.GetBytes(svgString);
var svg = Encoding.UTF8.GetString(bytes);


Hope this helps,
Fredrik
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 30-Oct-13 11:47am    
Sure, a 5, but only if UTF encoding is used in the existing file. This is usually the case and will automatically cover ASCII.
—SA
Sergey Alexandrovich Kryukov 30-Oct-13 11:54am    
I also suggested one attractive alternative, please see Solution 2. Your solution is of course credited.
—SA
Solution 1 fully resolve your problem (please see my comment), but I wonder why would you want this? Perhaps you should consider one other possibility: you can convert SVG to XAML and embed XAML into it as a resource of your WPF assembly.

One very good way to work with SVG, authoring vector images and export as XAML is using the wonderful open-source product called Inkscape:
http://en.wikipedia.org/wiki/Inkscape[^],
http://www.inkscape.org/[^].

Using XAML is a very good way of using vector graphics in WPF. Practically, you can get rid of all bitmap images at all (perhaps except very small iconic images and application/window icons). Among other things, you can do any transformations on your XAML images embedded as resources (you will need to use Canvas objects) and even animate them using animation provided by WPF or custom animation based on explicit threading.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900