Hi Experts
I m trying to retry images from database. My code is as below

DataTable tab = obj.createtable("Select pics from picto");//obj is the class in which createtable(string query) is function which returns datatable according to query

            byte[] ImgByte = (byte[])tab.Rows[0][0];
            FileStream fs = new FileStream("test.GIF", FileMode.Create);
            fs.Write(ImgByte, 0, ImgByte.Length);
            fs.Close();
            fs = null;
            pictureBox2.Image = Image.FromFile("test.GIF");

the last line give "out of memory " error.
Plz help me

>the last line give "out of memory " error.

Image file has invalid file-format.

I have tried another way.

DataTable tab = obj.createtable("Select pics from picto where id=1");
//obj is a class in which createtable(string query) is a function which returns datatable of query
            byte[] ImgByte = (byte[])tab.Rows[0][0];
            MemoryStream fs = new MemoryStream(ImgByte);
            fs.Write(ImgByte, 0, ImgByte.Length);
            MessageBox.Show(ImgByte.Length.ToString());
            Bitmap bm = new Bitmap(fs);
            pictureBox2.Image = bm;

this gives "Parameter no valid " error
plz help me.

.NET throws OutOfMemoryException if it does not recognize the image format.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.