110,534
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 将一组一维的字节数组转为图像。
/// </summary>
/// <exception cref="ArgumentNullException">Bytes 为 null 引用(在 Visual Basic 中为 Nothing)。</exception>
/// <exception cref="ArgumentException">Bytes 不包含图像数据。</exception>
/// <param name="Bytes">要转为图像的一组一维的字节数组。</param>
/// <returns>转换后的图像对象。</returns>
static public Bitmap BytesToBitmap(byte[] Bytes)
{
MemoryStream stream = null;
try
{
stream = new MemoryStream(Bytes);
return new Bitmap(stream);
}
catch (ArgumentNullException ex)
{
throw ex;
}
catch (ArgumentException ex)
{
throw ex;
}
finally
{
stream.Close();
}
}
if (dr.Read())
{
byte[] image_bytes = (byte[])dr["photo"];
MemoryStream ms = new MemoryStream(image_bytes);
System.Drawing.Image image = System.Drawing.Image.FromStream(ms);
pictureBox1.Image = image;
}
byte[] Bytes = (byte[])dr["photo"];
MemoryStream stream = new MemoryStream(Bytes);
pictureBox1.Image =new Bitmap(stream);
byte[] Bytes = (byte[])dr["photo"];
MemoryStream stream = new MemoryStream(Bytes);
pictureBox1.Image = Bitmap(stream);