没有合适的资源?快使用搜索试试~ 我知道了~
数据库中图像的读取cnnnnkdfkfgikriit nghjh
资源推荐
资源详情
资源评论
1.首先要求:可以选择图片,并显示在picturebox里面,然后将图片存储到数据库中(sql,assecc),注意存储的不是图片的路径,而是数据.
2.用datagrid显示数据库中的数据,单击某一行数据,在另一个picturebox显示出当前行的图片.
// Get bytes return from stored proc
byte[] b = (byte[])cmd.ExecuteScalar();
if(b.Length > 0)
{
// Open a stream for the image and write the bytes into it
System.IO.MemoryStream stream = new System.IO.MemoryStream(b, true);
stream.Write(b, 0, b.Length);
// Create a bitmap from the stream
Bitmap bmp = new Bitmap(stream);
// Check for scaling and assign the bitmap to the Picturebox
if( bmp.Width > 500 && bmp.Height > 300)
{
Bitmap bmp1 = new Bitmap(bmp, new Size(500,300));
pictureBox.Image = bmp1;
}
else
pictureBox.Image = bmp;
// Close the stream
stream.Close();
}
保存图片:将当前选择的显示在PictureBox中的图片转换成二进制流,存入数据库中
//图片保存
//ImageToByte(Image img) 将图片转换成二进制代码,然后存储在数据库中
public static byte[] ImageToByte(Image img)
2.用datagrid显示数据库中的数据,单击某一行数据,在另一个picturebox显示出当前行的图片.
// Get bytes return from stored proc
byte[] b = (byte[])cmd.ExecuteScalar();
if(b.Length > 0)
{
// Open a stream for the image and write the bytes into it
System.IO.MemoryStream stream = new System.IO.MemoryStream(b, true);
stream.Write(b, 0, b.Length);
// Create a bitmap from the stream
Bitmap bmp = new Bitmap(stream);
// Check for scaling and assign the bitmap to the Picturebox
if( bmp.Width > 500 && bmp.Height > 300)
{
Bitmap bmp1 = new Bitmap(bmp, new Size(500,300));
pictureBox.Image = bmp1;
}
else
pictureBox.Image = bmp;
// Close the stream
stream.Close();
}
保存图片:将当前选择的显示在PictureBox中的图片转换成二进制流,存入数据库中
//图片保存
//ImageToByte(Image img) 将图片转换成二进制代码,然后存储在数据库中
public static byte[] ImageToByte(Image img)
资源评论
yp1990103
- 粉丝: 5
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功