二进制读取图片无法正常显示
-----存储的部分代码,partImg为非空的BITMAPMemoryStream stream = new MemoryStream();
partImg.Save(stream, ImageFormat.Bmp);
fileByteArray = new Byte[stream.Length];
stream.Position = 0;
stream.Read(fileByteArray, 0, fileByteArray.Length);
stream.Close();
partImg.Dispose();
-------把fileByteArray存储到HeadPortrait字段后读取出来显示,
Byte[] Cfiles = (Byte[])getUser.HeadPortrait;
Response.BinaryWrite(Cfiles);
Response.End();
显示区域都是黑色的,不知道是哪里出了问题,如方法有错,请怎么把一个bitMap类型转换成二进制存储并显示?
--------------------编程问答-------------------- <img src="show.aspx?id=x" />
show.aspx
private void Page_Load(object sender, System.EventArgs e)
{
string strID = Request.QueryString["id"];
string sqlstr = "select photo from Tb where id=@id";
SqlConnection myConnection = new SqlConnection(connstr);
SqlCommand myCommand = new SqlCommand(sqlstr, myConnection);
myCommand.AddWithValue("@id",strID )
try
{
myConnection.Open();
SqlDataReader dr= myCommand.ExecuteReader(CommandBehavior.CloseConnection);
if(dr.Read())
{
Response.Clear();
Response.ContentType = "image/gif";
Response.BinaryWrite((byte[])dr["photo"]);
}
myConnection.Close();
}
catch (SqlException ex)
{
}
Response.End();
}
--------------------编程问答-------------------- 1楼的,我的SHOW页面跟你一样的,就是显示出来的是一张黑色图 --------------------编程问答-------------------- 1楼 正确!!
补充:.NET技术 , ASP.NET