我正在为此开发应用程序,我想捕获图像并再次存储在数据库中 ANA 想要检索网页上的图像,我尝试使用此代码
context.Response.ContentType = "image/jpeg";
Stream strm = DisplayImage(theID);
byte[] buffer = new byte[2048];
int byteSeq = strm.Read(buffer, 0, 2048);
while (byteSeq > 0)
{
context.Response.OutputStream.Write(buffer, 0, byteSeq);
byteSeq=strm.Read(buffer, 0, 2048);
}
}
public Stream DisplayImage(int theID)
{
DB_Connection();
string sql = "SELECT Image_Data FROM Image_T WHERE Img_ID = '" + theID + "'";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("Img_ID", theID);
object imgg = (byte[])cmd.ExecuteScalar();
//byte[] imagedata = (byte[])cmd.ExecuteScalar();
try
{
return new MemoryStream((byte[])imgg);
}
catch
{
return null;
}
finally
{
con.Close();
}
}
在按钮点击呼叫
protected void Button1_Click(object sender, EventArgs e)
{
Image1.ImageUrl = "Handler1.ashx?id=" + 101;
}