C#读取 image类型

fhuibo 2006-07-05 12:00:27
怎么实现从SQLSERVER 2000中的 image类型 读出图片并保存到计算机为 .jpeg或.jpg 或.bmp的形式
...全文
390 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
marvelstack 2006-07-07
  • 打赏
  • 举报
回复
数据库中操作图片
How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET
http://support.microsoft.com/default.aspx?scid=kb;EN-US;309158


DataGrid显示图片(物理路径式和Stream流式)和添加图片到数据库
http://singlepine.cnblogs.com/articles/288027.html
SolidGL 2006-07-06
  • 打赏
  • 举报
回复
see see
Eddie005 2006-07-05
  • 打赏
  • 举报
回复
System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection(".....");
System.Data.SqlClient.SqlCommand cm = new System.Data.SqlClient.SqlCommand("Select theImage from table1 where id=1",cnn);
System.Data.SqlClient.SqlDataReader dr = cm.ExecuteReader();
if(dr.Read())
{
byte[] bytes = (byte[])dr[0];
System.IO.MemoryStream str = new System.IO.MemoryStream(bytes);
System.Drawing.Image img = System.Drawing.Image.FromStream(str);
img.Save("test.jpg");
}
cnn.Close();
cjnet 2006-07-05
  • 打赏
  • 举报
回复
參考這兩個函數:
//ImageToByte(Image img)
public static byte[] ImageToByte(Image img)
{
byte[] byt = null;
ImageConverter imgCvt = new ImageConverter();
object obj = imgCvt.ConvertTo(img, typeof(byte[]));
byt = (byte[])obj;
return byt;
}

//ByteToImage(byte[] byt),先用DataReader在數據庫中讀取byte[]
public static Image ByteToImage(byte[] bytImage)
{
Image img = null;
if (bytImage.Length == 0)
{
return img;
}
else
{
ImageConverter imgCvt = new ImageConverter();

object obj = imgCvt.ConvertFrom(bytImage);
img = (Image)obj;
return img;
}
}
Knight94 2006-07-05
  • 打赏
  • 举报
回复
Some changed based on Eddie005(♂) №.零零伍 (♂)

System.IO.MemoryStream str = new System.IO.MemoryStream(bytes, true);
str.Read( bytes, 0, bytes.Length );
System.Drawing.Image img = System.Drawing.Image.FromStream(str);
kaixin110 2006-07-05
  • 打赏
  • 举报
回复
msdn.com
yistudio 2006-07-05
  • 打赏
  • 举报
回复
参考一下http://yistudio.cnblogs.com
fhuibo 2006-07-05
  • 打赏
  • 举报
回复
Eddie005(♂) №.零零伍 (♂)
的System.Drawing.Image img = System.Drawing.Image.FromStream(str);
报错,
System.ArgumentException: 使用了无效参数,
请问兄弟应怎样转化参数
mmens 2006-07-05
  • 打赏
  • 举报
回复
楼上抢先了。呵呵。。。

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧