C# windows 应用程序中怎么根据给定地址显示图片? 1.数据库中某个字段存有图片的本地地址,怎么根据这个地址在form里显示图片?2.如果这个sql server数据库的字段存的不是本地地址,而是image类型的话,怎么在form里显示这个图片?急,感谢各位了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 数据库存图片一般采取两种方式;1、存储图片地址。2、存储图片本身(用image字段)对于前者,与本地没有任何区别,你只要读出地址字符串即可。对于后者,由于它直接存储的是二进制数据,你需要还原成Image对象。 MemoryStream stream = new MemoryStream (); //数据库byte[] image = (byte[]) command.ExecuteScalar ();//把文件读成byte[]就不用说了吧byte[] image = 从文件读取stream.Write (image, 0, image.Length);Bitmap bitmap = new Bitmap (stream); 弄成了Bitmap ,你就可以显示了或者你还可以弄成Image 1、如果是地址的话得到这个地址后pictureBox.ImageLocation=地址就可以了2、但如果是image类型用lovefootballbyte[]===>MemoryStream===>Image 1、如果是地址,得到这个地址后将pictureBox.ImageLocation=地址;2、如果是image类型用private void GetImage(){if (this.pictureBox1.Image!=null){this.pictureBox1.Image.Dispose();}int num=this.dataGrid1.CurrentRowIndex;if (num==-1){return;}try{if(ds.Tables["table"].Rows[num]["Photo"]!=Convert.DBNull){byte[] bytes=(byte[])ds.Tables["table"].Rows[num]["Photo"];MemoryStream memStream=new MemoryStream(bytes);Bitmap bitmap=new Bitmap(memStream);memStream.Close();this.pictureBox1.Image=bitmap;}else{this.pictureBox1.Image=null;}}catch(Exception err){MessageBox.Show(err.Message);}} 求助~ 有没有人能帮我远程C#连接一下数据库 字符串边数组的方式 microsoftreportviewer? 如何设置窗体的类名 winform的ClassName 关于DataReader的问题 问一下petshop是不是没有后台管理啊 可不可以给我以个c#的完整的例子 最好是一个有多个类的程序源码 定制控件的属性问题 Pattern思想討論 2个句柄的问题,高手来看看. C#调用DLL的问题 .net c#中如何获取sql存储过程返回的参数?
1、存储图片地址。
2、存储图片本身(用image字段)对于前者,与本地没有任何区别,你只要读出地址字符串即可。
对于后者,由于它直接存储的是二进制数据,你需要还原成Image对象。
//数据库
byte[] image = (byte[]) command.ExecuteScalar ();
//把文件读成byte[]就不用说了吧
byte[] image = 从文件读取
stream.Write (image, 0, image.Length);
Bitmap bitmap = new Bitmap (stream);
弄成了Bitmap ,你就可以显示了
或者你还可以弄成Image
2、但如果是image类型用lovefootball
byte[]===>MemoryStream===>Image
2、如果是image类型用
private void GetImage()
{
if (this.pictureBox1.Image!=null)
{
this.pictureBox1.Image.Dispose();
}
int num=this.dataGrid1.CurrentRowIndex;
if (num==-1)
{
return;
}
try
{
if(ds.Tables["table"].Rows[num]["Photo"]!=Convert.DBNull)
{
byte[] bytes=(byte[])ds.Tables["table"].Rows[num]["Photo"];
MemoryStream memStream=new MemoryStream(bytes);
Bitmap bitmap=new Bitmap(memStream);
memStream.Close();
this.pictureBox1.Image=bitmap;
}
else
{
this.pictureBox1.Image=null;
}
}
catch(Exception err)
{
MessageBox.Show(err.Message);
}
}