如何将图像转换为Html与C#的数据URI? [英] how to convert Image to Data URI for Html with C#?

查看:65
本文介绍了如何将图像转换为Html与C#的数据URI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将图像转换为数据URL(嵌入图像)在HTML的Win应用程序中,我需要
数据URL(嵌入图像)进行图像处理。

h2_lin>解决方案

  public static string GetDataURL(string imgFile)
{
return< img src = \data:图像/
+ Path.GetExtension(imgFile).Replace( )
+ ; BASE64,
+ Convert.ToBase64String(File.ReadAllBytes(imgFile)) +\/>;
}


I need convert image to Data URL (embedding Image) in the Win-application for HTML and I need Data URL (embedding Image) to image.

解决方案

        public static string GetDataURL(string imgFile)
        {
            return "<img src=\"data:image/" 
                        + Path.GetExtension(imgFile).Replace(".","")
                        + ";base64," 
                        + Convert.ToBase64String(File.ReadAllBytes(imgFile)) + "\" />";
        }

这篇关于如何将图像转换为Html与C#的数据URI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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