byte[] arr = Convert.FromBase64String(inputStr);
MemoryStream ms = new MemoryStream(arr ,0, arr.Length);
Bitmap bmp = new Bitmap(ms);
bmp.Save(ConfigData.IDCardPath + ID + ".jpg", ImageFormat.Jpeg);
这一句报参数无效的错误:Bitmap bmp = new Bitmap(ms);
网上看到都是这么做的,求教各路大神啊
MemoryStream ms = new MemoryStream(arr ,0, arr.Length);
==>改下面的试试,而且你的inputStr格式是否正确。。。不包含data:images/gif;这个数据
MemoryStream ms = new MemoryStream(arr);
arr是不是null啊
你那个字符串是不是图片的base64要弄清楚啊。
试试这段代码:
byte[] buffer = Convert.FromBase64String(headImg);
MemoryStream ms = new MemoryStream(buffer);
Bitmap bmp = Image.FromStream(ms) as Bitmap;
string filePath = "C:/File/test.png"
DirectoryInfo TheFolder = new DirectoryInfo(filePath);
if (!TheFolder.Exists)
{
Directory.CreateDirectory(filePath);
}
bmp.Save(filePath);
File.WriteAllBytes("D:\yourfile.jpg", Convert.FromBase64String(s)); s是base64字符串,一句话搞定,把图片存在D盘下,我也是和你一样的错误,找了半天找到了这个