显示图片问题 请教各位大哥们一个问题:我现在已经将图片以 image 数据类型 存在了 sql2005 数据库中,现在想在网页的 DetailsView 控件中按照一定的大小显示出来,请问要怎么做?谢谢指点 !~~~~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void ShowImage(string sql) { string sql = "select Photo from UserPhoto where UserNo='" + userno +"'"; SqlCommand cmd = new SqlCommand(sql, conn); conn.Open(); byte[] b= (byte[])cmd.ExecuteScalar(); if (b.Length 〉 0) { MemoryStream stream = new MemoryStream(b, true); stream.Write(b, 0, b.Length); Bitmap bitmap1 = new Bitmap([宽度],[高度]); bitmap1.FromStream(stream); pictureBox1.Image = bitmap1; stream.Close(); } conn.Close(); } 是啊,应该将图片地址存到数据库中,控制图片大小用width 和height控制就行了 保存中数据库代码string fileName; fileName=this.file.PostedFile.FileName.Substring(this.file.PostedFile.FileName.LastIndexOf("\\")+1); DataBase db=new DataBase(); if(this.file.PostedFile.ContentType.IndexOf("image")<0) { Message.Alert("file","上传图片格式不对",Page); return; } byte[] Ofb=new byte[this.file.PostedFile.ContentLength]; this.file.PostedFile.InputStream.Read(Ofb,0,this.file.PostedFile.ContentLength); //db.InsterDate("insert into 产品图片(图片,图片类型) values('"+Ofb+"','"+fileName.Substring(fileName.LastIndexOf(".")+1)+"')"); //OleDbDataReader dr=db.GetReader("select 图片 from 产品"); //while(dr.Read()) //{ // Image1.ImageUrl= //} string sql="insert into 产品图片(图片,图片类型) values(@ImageData,@ImageType)"; SqlConnection mycon=CommClass.Conn.CreateConn(); SqlCommand mycom=new SqlCommand(sql,mycon); mycom.Parameters.Add("@ImageData",SqlDbType.Image); mycom.Parameters.Add("@ImageType",SqlDbType.NVarChar); mycom.Parameters["@ImageData"].Value=Ofb; mycom.Parameters["@ImageType"].Value=fileName.Substring(fileName.LastIndexOf(".")+1); mycon.Open(); mycom.ExecuteNonQuery(); mycon.Close();读取SqlConnection mycon=CommClass.Conn.CreateConn(); mycon.Open(); SqlCommand mycom=new SqlCommand("select * from 产品图片",mycon); SqlDataReader dr=mycom.ExecuteReader(); if(dr.Read()) { Response.ContentType=dr["图片类型"].ToString(); //类型一定要设置 Response.BinaryWrite((byte[])dr["图片"]); }总结截图 Form程序给textbox赋值的问题 谁用过Goole API做过或许天气预报的东西~~ 请问怎么从一个表更新另一个表~ 如何使用WebBrowser打开显示本地一个htm文件? vs2005串口控件问题 在C#Form中怎么样显示pdf?高手救命 一个线程与实例名的问题 报表就叫报表呗,为啥还叫“水晶报表”? 怎样知道API中消息的常量值? 求解,MSChart高手进 Datatable (Group by) 如何连接压缩包中的Excel文件
private void ShowImage(string sql)
{
string sql = "select Photo from UserPhoto where UserNo='" + userno +"'";
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
byte[] b= (byte[])cmd.ExecuteScalar();
if (b.Length 〉 0)
{
MemoryStream stream = new MemoryStream(b, true);
stream.Write(b, 0, b.Length);
Bitmap bitmap1 = new Bitmap([宽度],[高度]);
bitmap1.FromStream(stream);
pictureBox1.Image = bitmap1;
stream.Close();
}
conn.Close();
}
fileName=this.file.PostedFile.FileName.Substring(this.file.PostedFile.FileName.LastIndexOf("\\")+1);
DataBase db=new DataBase();
if(this.file.PostedFile.ContentType.IndexOf("image")<0)
{
Message.Alert("file","上传图片格式不对",Page);
return;
}
byte[] Ofb=new byte[this.file.PostedFile.ContentLength];
this.file.PostedFile.InputStream.Read(Ofb,0,this.file.PostedFile.ContentLength);
//db.InsterDate("insert into 产品图片(图片,图片类型) values('"+Ofb+"','"+fileName.Substring(fileName.LastIndexOf(".")+1)+"')");
//OleDbDataReader dr=db.GetReader("select 图片 from 产品");
//while(dr.Read())
//{
// Image1.ImageUrl=
//}
string sql="insert into 产品图片(图片,图片类型) values(@ImageData,@ImageType)";
SqlConnection mycon=CommClass.Conn.CreateConn(); SqlCommand mycom=new SqlCommand(sql,mycon);
mycom.Parameters.Add("@ImageData",SqlDbType.Image);
mycom.Parameters.Add("@ImageType",SqlDbType.NVarChar); mycom.Parameters["@ImageData"].Value=Ofb;
mycom.Parameters["@ImageType"].Value=fileName.Substring(fileName.LastIndexOf(".")+1);
mycon.Open(); mycom.ExecuteNonQuery();
mycon.Close();
读取SqlConnection mycon=CommClass.Conn.CreateConn();
mycon.Open();
SqlCommand mycom=new SqlCommand("select * from 产品图片",mycon);
SqlDataReader dr=mycom.ExecuteReader();
if(dr.Read())
{
Response.ContentType=dr["图片类型"].ToString(); //类型一定要设置
Response.BinaryWrite((byte[])dr["图片"]);
}总结截图