2011-07-29 63 views

回答

3

你必须创建一个返回图像的HTTP处理程序

public void ProcessRequest(HttpContext context) 
     { 
      Byte[] yourImage = //get your image byte array 
      context.Response.BinaryWrite(yourImage); 
      context.Request.ContentType = "image/jpeg"; 
      context.Response.AddHeader("Content-Type", "image/jpeg"); 
      context.Response.AddHeader("Content-Length", (yourImage).LongLength.ToString()); 
      con.Close(); 

      context.Response.End(); 
      context.Response.Close(); 
     } 

您可以可以做到这一点通过创建从Visual Studio中GenericHandler文件类型,并添加以前的代码,那么你可以调用您可以编写通用的处理程序的URL作为图像源

+0

非常感谢。这是一个很好的解决方案,我的意思是创建一个GenericHandler文件。 –

+0

不客气! –

+0

@SamirAdel我认为BinaryWrite应该在添加标题后得到正确的文件类型。 –

2
MemoryStream ms = new MemoryStream(byteArrayFromDB); 
    Image returnImage = Image.FromStream(ms); 
0

你可能想在这个看起来还有

byte[] imageBytes = (byte[]) imageReader.GetValue(0);  
MemoryStream ms = new MemoryStream(imageBytes); 
FileStream fs = File.OpenWrite(imagePath); 
fs.Write(ms.GetBuffer(), 0, ms.Position()); 
相关问题