你最好用Datareader读blob内容(byte[])假设你读取的数据为byte[] data,显示图片用picturebox,我试过可以的 byte[] data;string sqlText = "SELECT img_data, img_contenttype FROM Image WHERE img_pk = " + ImageId; SqlConnection connection = new SqlConnection( connstring ); SqlCommand command = new SqlCommand( sqlText, connection); //open the database and get a datareader connection.Open(); SqlDataReader dr = command.ExecuteReader(); if ( dr.Read()) { data=(byte[]) dr["img_data"] ;
}MemoryStream ms = new MemoryStream(data);Image img = new Bitmap(ms); this.pictureBox1.Image=img;
DataRow dataRowProduct = dataSet.Tables["Product"].Rows.Find(currentProductID);
this.byteProductImage = new byte[((byte[])dataRowProduct["ImageData"]).Length];
this.byteProductImage = (byte[])dataRowProduct["ImageData"];
MemoryStream memoryStreamImage = new MemoryStream();
memoryStreamImage.Write(this.byteProductImage,0,this.byteProductImage.Length);bitmapProduct = new Bitmap(memoryStreamImage);this.imageProduct = this.bitmapProduct;
this.imageWidth = this.bitmapProduct.Width;
this.imageHeight = this.bitmapProduct.Height;
memoryStreamImage.Close();this.labelProductImage.Image = this.imageProduct;
this.labelProductImage.Width = this.imageWidth;
this.labelProductImage.Height = this.imageHeight;
this.labelProductImage.Left = (this.Width/2)-((int)(this.imageWidth/2));
this.labelProductImage.Top = (this.Height/2)-((int)(this.imageHeight/2));
this.labelProductImage.Visible = true;
不知你们的是怎么实现的呢?
byte[] data;string sqlText = "SELECT img_data, img_contenttype FROM Image WHERE img_pk = " + ImageId; SqlConnection connection = new SqlConnection( connstring );
SqlCommand command = new SqlCommand( sqlText, connection); //open the database and get a datareader
connection.Open();
SqlDataReader dr = command.ExecuteReader();
if ( dr.Read())
{
data=(byte[]) dr["img_data"] ;
}MemoryStream ms = new MemoryStream(data);Image img = new Bitmap(ms);
this.pictureBox1.Image=img;
Image ima=new Bitmap(@"H:\图片\素材库\箭头动画\07arrow15.gif");
this.pictureBox1.Image=ima;