将SVG图像转换为Base64 [英] Convert SVG image to Base64

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

问题描述

你好

我正在尝试将图像转换为Base64字符串并将其显示在我的WPF应用程序中

i am trying to Convert Image to Base64 string and display it in my WPF Application

转换代码

  Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); 

            Nullable<bool> result = dlg.ShowDialog();

            if (result == true)
            {
                byte[] imageArray = System.IO.File.ReadAllBytes(dlg.FileName);
                string base64ImageRepresentation = Convert.ToBase64String(imageArray);
              
                textBox.Text = base64ImageRepresentation;
               
               
            }

将base64显示为图像的代码

Code to display base64 as Image 

 byte[] binaryData = Convert.FromBase64String(textBox.Text);

            BitmapImage bi = new BitmapImage();
            bi.BeginInit();
            bi.StreamSource = new MemoryStream(binaryData);
            bi.EndInit();
 
            imageSection.Source = bi;

它适用于所有图像格式(Gif,Jpg,Png)的SVG.

It work well for all Image Format(Gif, Jpg, Png) exept SVG.

如何为SVG格式自定义代码?

How to customize my code for SVG format ? 

预先感谢

CPGTech中心

推荐答案


嗨CPGtech,


Hi   CPGtech,

>>如何为SVG格式自定义我的代码?

据我所知,SVG是一种用于描述XML中的二维图形的语言. SVG允许使用三种类型的图形对象:矢量图形形状(例如,由直线和曲线组成的路径),图像和文本.

As far as I know, SVG is a language for describing two-dimensional graphics in XML. SVG allows for three types of graphic objects: vector graphic shapes (e.g., paths consisting of straight lines and curves), images and text.

因此,也许您应该先将SVG转换为Image,然后再将图像转换为Base64.

So, May be you should convert SVG to Image firstly, then convert the image to Base64.

您可以尝试使用某些第三方扩展.

You can try to use some third-party extended.

1:SVG渲染引擎
https://svg.codeplex.com/

1: SVG Rendering Engine
https://svg.codeplex.com/

在C#.NET中使用矢量(SVG)图形:
https://lasithapetthawadu.wordpress.com/2014/02 /24/using-vector-svg-graphics-in-c-net/

Using Vector (SVG) Graphics in C# .NET:
https://lasithapetthawadu.wordpress.com/2014/02/24/using-vector-svg-graphics-in-c-net/

2:SharpVectors-重新加载SVG#:此项目提供了一个C#库,用于在WPF应用程序中解析,转换和查看SVG文件.
https://sharpvectors.codeplex.com/

2: SharpVectors - SVG# Reloaded: This project provides a C# library for parsing, converting and viewing the SVG files in WPF applications. 
https://sharpvectors.codeplex.com/

如何使用C#[SharpVectors]将SVG文件转换为PNG:
http://cisharp.blogspot.sg/2015/02/how-to-convert-svg-files-to-pngs-using-c.html

How to convert SVG files to PNGs using C#[SharpVectors]:
http://cisharp.blogspot.sg/2015/02/how-to-convert-svg-files-to-pngs-using-c.html


以下链接供您参考.


The following link for your reference.

SVG到PNG批处理转换器(C#.NET 2012):
http://danbarbulescu.com/svg-png-batch-converter-c-net-2012 /

SVG to PNG batch converter (C# .NET 2012):
http://danbarbulescu.com/svg-png-batch-converter-c-net-2012/

在C#中将SVG图像转换为PNG:
http://harriyott.com/2008/05/converting-svg-images- to-png-in-c

Converting SVG images to PNG in C#:
http://harriyott.com/2008/05/converting-svg-images-to-png-in-c


注意:此响应包含对第三方万维网站点的引用. Microsoft为方便您而提供此信息. Microsoft不控制这些站点,也没有测试在这些站点上找到的任何软件或信息;所以, Microsoft无法对在此找到的任何软件或信息的质量,安全性或适用性做出任何陈述.使用Internet上发现的任何软件都存在固有的危险,Microsoft提醒您确保自己 从Internet上检索任何软件之前,请完全了解风险.


Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

最好的问候,

Yohann Lu

Yohann Lu


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

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