Stream anstelle von FileStream

JK_net

Erfahrenes Mitglied
Hallo!

Kann mir jemand erklären, wie ich folgenden Code nicht als Datei speichere über FileStream, sondern direkt mit Image.FromStream() an eine PictureBox übergebe?

Code:
FileStream fs; 
BinaryWriter bw;
int bufferSize = 100;
byte[] outbyte = new byte[bufferSize];
long retval;
long startIndex = 0;
 
myReader = myContacts.ExecuteReader();
if (myReader.HasRows)
{
while (myReader.Read())
{ 
	fs = new FileStream(Application.StartupPath + "\\system\\user\\icons\\" + this.cboUser.Text + ".png", FileMode.OpenOrCreate, FileAccess.Write);
	bw = new BinaryWriter(fs);
	startIndex = 0;
	retval = myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize);
	while (retval == bufferSize)
	{
	 bw.Write(outbyte);
	 bw.Flush();
	 startIndex += bufferSize;
	 retval = myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize);
	}
	bw.Write(outbyte, 0, (int)retval - 1);
	bw.Flush();
	bw.Close();
	fs.Close();
}
this.picImage.Image = Image.FromFile(Application.StartupPath + "\\system\\user\\icons\\" + this.cboUser.Text + ".png");
}

Ich weiß, dass es unüblich ist Bilder in einer DB zu speichern... ;)
Vielleicht können wir da ja mal kurz drüber hinwegsehen...

Vielen Dank im Voraus!

MfG
Jens
 
Zurück