Я хочу импортировать изображение из моей базы данных MySQl, но я не знаю, как импортировать BLOB-объект в Picturebox.
Моя картинка - элемент reader [3] , но я не знаю, почему мои параметры недействительны . Я перепробовал много разных методов, но мой поток всегда пуст или мои параметры неверны.
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
}