将图像转换为base64字符串 [英] Convert image to base64 string

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

问题描述

string im = "sun.jpg";
byte[] imageArray = File.ReadAllBytes(@"~\image\" + im);
string base64ImageRepresentation = Convert.ToBase64String(imageArray);







图片我保存在项目本身,当我给出的位置图片

它要去c盘而不是在项目中搜索

所以我收到了这个错误。








Image i have saved in project itself and when i am giving the location of image
its going to c drive and its not searching in project
so i am getting this error.


ERROR:

Could not find a part of the path 'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\~\image\sun.jpg'.

推荐答案

指定的图像路径

'C:\Program Files \ Common Files \ Mysrosoft Shared\DevServer\10.0\〜\\ \\ image\sun.jpg'

不存在或找不到目录。





Specified image path
'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\~\image\sun.jpg'
is not really exist or directory is not found.


<br />
use instead adding project resources or Environment.StartupPath<br />





+确保图像文件与您执行的应用程序位于同一文件夹中。



+ make sure that image file is located on same folder with application that you've executed.


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

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