2013-05-03 5 views
-1

이미지를 지정된 문자열 경로에 저장하려고 할 때마다 계속 GDI + 오류가 발생합니다. 이것은 코드입니다. 제발 할 수있어?바이트 배열을 이미지로 변환

 System.Drawing.Image newImage; 
     byte[] b= (byte[])Session["Image"]; 
     using (MemoryStream stream = new MemoryStream(b)) 
     { 
      newImage = System.Drawing.Image.FromStream(stream); 
      newImage.Save("C:\\test.png"); //this is where the GDI+ error is thrown 
      Image1.Attributes.Add("src", "C:\\test"); 

     } 
+2

오류가 무엇입니까 :

그렇지 않으면 당신은 직접 바이트를 저장할 수 있습니까? 서버 사용자가'C : \ '에 쓸 수있는 권한을 가지고 있습니까? –

+0

오류는'Session [ "Image"]'에 유효하지 않은 데이터가 들어 있다고 말합니다. 바인드 (바이트 배열 - 이미지 배열) 데이터를'Session'에 바인딩하는 코드를 보여줍니다. – adatapost

+0

Chart1.SaveImage (m, ChartImageFormat.Png); // m은 memorystream 변수입니다. Session.Add ("Image", m.ToArray()); – user2343504

답변

1

바이트를 이미지로 변환 한 다음 이미지를 다시 바이트로 변환해야합니까?

File.WriteAllBytes("C:\\test.png", (byte[])Session["Image"]); 
관련 문제