如何从数据库到图片框检索图像..请帮助我.. !!!!!! 1 [英] how to retrieve image from database to picturebox.. Please HELP ME..!!!!!!1
本文介绍了如何从数据库到图片框检索图像..请帮助我.. !!!!!! 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
检索图像时出现错误-内存不足.
我用于搜索包括图像在内的所有字段的代码是---
I am getting error while retrieving image--Out of memory.
and my code for searching all fields including image is---
DataTable dt = new DataTable();
dt = ds.Tables["StudentDetails"];
if (pictureBox1.Image != null)
{
pictureBox1.Image.Dispose();
}
FileStream FS1 = new FileStream("image.jpg", FileMode.Create);
foreach (DataRow dataRow in dt.Rows)
{
if (dataRow[1].ToString() == cboxStudent_ID.Text)
{
byte[] blob = (byte[])dataRow[54];
FS1.Write(blob, 0, blob.Length);
FS1.Close();
FS1 = null;
pictureBox1.Image = Image.FromFile("image.jpg");
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
}
推荐答案
您不需要这样做:您可以使用Memorystream将byte []转换为图像:
You don''t need to do that: you can just use a Memorystream to convert from a byte[] to an image:
MemoryStream ms = new MemoryStream(bytes);
Image returnImage = Image.FromStream(ms);
另一件事是,您需要查看将现有图像放置在循环内部而不是外部-您可能会或可能不会在循环内部找到您的ID.
The other thing is that you need to look at disposing the existing image inside the loop instead of outside - you may or may not find your ID inside the loop.
这篇关于如何从数据库到图片框检索图像..请帮助我.. !!!!!! 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文