我想从MySQl数据库导入图片,但是我不知道如何将Blob导入图片框。 我的图片是元素阅读器[3] ,但我不知道为什么我的参数无效。我尝试了许多不同的方法,但是我的Stream始终为空或参数无效。
long CurrentIndex = 0;
int Buffersize = 100;
long BytesReturned;
int positiontop = 80;
int positionl = 100;
byte[] bts = new byte[Buffersize];
while (reader.Read())
{
FileStream fs = new FileStream(reader["Bild"].ToString(),FileMode.OpenOrCreate, FileAccess.Write);
BinaryWriter writer = new BinaryWriter(fs);
CurrentIndex = 0;
BytesReturned = reader.GetBytes(3, CurrentIndex, bts, 0, Buffersize);
while (BytesReturned == Buffersize)
{
writer.Write(bts);
writer.Flush();
CurrentIndex += Buffersize;
BytesReturned = reader.GetBytes(3, CurrentIndex, bts, 0, Buffersize);
}
writer.Write(bts, 0, (int)BytesReturned);
writer.Flush();
writer.Close();
fs.Close();
PictureBox pbx = new PictureBox() { Size = new Size(40, 20), BackgroundImageLayout = ImageLayout.Stretch };
pbx.Image = (Bitmap)((new ImageConverter()).ConvertFrom(bts)); //Exeption occurs here
}