2017-03-20 11 views
0

私は がどのように私はこのような何かをしたいバイト[]変換セッション値[]

に変換することができ、base64形式でセッションにイメージを格納します。

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

あなたはバイト配列にbase64文字列をデコードするConvert.FromBase64String方法を必要としています。

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

その仕事..ありがとう –