将svg转换为byte [] [英] convert svg to byte []

查看:181
本文介绍了将svg转换为byte []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我在tabContainer中使用svg文件,例如我的标签背景。用户应该能够动态添加,删除或更改选项卡的背景并将其保存到数据库。图像数据库中的字段是byte [](与通常的图像一样)。可以提供将svg文件转换为byte []的示例或链接吗?或者可能有更好的方法将svg文件保存到数据库?

提前感谢。

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.

推荐答案

使用 System.Text.Encoding



Use System.Text.Encoding.

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





希望这会有所帮助,

Fredrik



Hope this helps,
Fredrik


解决方案1完全解决您的问题(请参阅我的评论),但我想知道您为什么要这样做?也许您应该考虑另一种可能性:您可以将SVG转换为XAML并将XAML作为WPF程序集的资源嵌入其中。



一种非常好的工作方式SVG,创作矢量图像并导出为XAML正在使用名为Inkscape的精彩开源产品:

http: //en.wikipedia.org/wiki/Inkscape [ ^ ],

http://www.inkscape.org/ [ ^ ]。



使用XAML非常在WPF中使用矢量图形的好方法。实际上,您可以完全摆脱所有位图图像(可能除了非常小的图标图像和应用程序/窗口图标)。除此之外,您可以对作为资源嵌入的XAML图像进行任何转换(您将需要使用 Canvas 对象),甚至使用WPF提供的动画或自定义动画对它们进行动画处理基于显式线程。



-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


这篇关于将svg转换为byte []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆