2017-03-20 25 views
0

我存储图像成Base64格式会议, 我怎样才能把它转换成字节[]转换会话值转化成byte []

我想要做这样的事情:

Byte[] bytes =(Byte[]) Session["picimg"]; 

它不是加工。

这是我的代码:

StreamReader reader = new StreamReader(Request.InputStream); 
String Data = Server.UrlDecode(reader.ReadToEnd()); 
reader.Close(); 
DateTime nm = DateTime.Now; 
string date = nm.ToString("yyyymmddMMss"); 
     //used date for creating Unique image name 

Session["capturedImageURL"] = Server.MapPath("Userimages/") + date + ".jpeg"; 

Session["Imagename"] = date + ".jpeg"; 
// We can use name of image where ever we required that why we are storing in Session 

     drawimg(Data.Replace("imgBase64=data:image/png;base64,", String.Empty), Session["capturedImageURL"].ToString()); 

     // it is method 
     // passing base64 string and string filename to Draw Image. 
Session["picimg"] = (Data.Replace("imgBase64=data:image/png;base64,", String.Empty)); 

     Byte[] bytes =(Byte[]) Session["picimg"]; 
     System.IO.File.WriteAllBytes(@"Userimages", bytes); 
+0

将图像缓存到SessionState并不是一个好习惯。您的服务器将很快耗尽内存。 – Win

回答

0

您需要Convert.FromBase64String方法以base64字符串解码成字节数组。

byte[] Bytes = Convert.FromBase64String(DataInBase64); 
+0

其工作..感谢 –