gamedev

gamedev

  • NA
  • 6
  • 0

get byte[] from a database

Feb 6 2005 8:55 AM
I've saved an image (converting in byte[]) inside a field of my database, now i would read the database getting these bytes[] and convertering into the original image... I use this code: OleDbDataReader myReader; .... .. instance myReader here... .... myCommand.ExecuteReader(); MemoryStream myStream; int buffersize = 300000; // doubt n°2 = but if my image is bigger of 300000 ??? Byte[] outbyte = new Byte[299999]; myStream = new MemoryStream(outbyte, 0, 300000, true); myReader.GetBytes(5, 0, outbyte, 0, buffersize); myStream.Flush(); // am i just deleting all bytes unused? pictureBox1.Image = Image.FromStream(myStream); myStream.Close(); but this code doesn't work, where do i wrong? Then I've tried to change the code in this way: MemoryStream myStream; Byte[] outbyte = (Byte[])myReader["Image"]; myStream = new MemoryStream(outbyte); pictureBox1.Image = Image.FromStream(myStream); myStream.Close(); but this doesn't work too.

Answers (1)