G
Guest
I'm trying to convert an Image file to a byte[] array .
Later in my code I'm trying to create a new Image from this byte[] array as
a restored Image.
But when I try to save the restored Image to a Bitmap file I get a generic
DGI exception saying:
"A generic error occurred in GDI+".
Here is the code I'm using:
////// Loading a bitmap file to a byte[] array ////////////////////////
Bitmap bmpIn = Bitmap.FromFile("Picture.bmp", true) as Bitmap;
MemoryStream msIn = new MemoryStream();
bmpIn.Save(msIn,
System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()[0], null);
msIn.Close();
byte[] buf = msIn.GetBuffer();
/////// Creating a new bitmap from the buf byte[] array /////////
Bitmap bmpOut;
MemoryStream msOut = new MemoryStream();
msOut.Write(buf, 0, buf.Length);
bmpOut = new Bitmap(msOut);
msOut.Close();
bmpOut.Save("ImageOut.bmp", System.Drawing.Imaging.ImageFormat.Bmp); //
ERROR: Throw the above exception !!!!
Can anybody tell what is the problem that causes the DGI error ?
Any help will be highly appreciated.
Later in my code I'm trying to create a new Image from this byte[] array as
a restored Image.
But when I try to save the restored Image to a Bitmap file I get a generic
DGI exception saying:
"A generic error occurred in GDI+".
Here is the code I'm using:
////// Loading a bitmap file to a byte[] array ////////////////////////
Bitmap bmpIn = Bitmap.FromFile("Picture.bmp", true) as Bitmap;
MemoryStream msIn = new MemoryStream();
bmpIn.Save(msIn,
System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders()[0], null);
msIn.Close();
byte[] buf = msIn.GetBuffer();
/////// Creating a new bitmap from the buf byte[] array /////////
Bitmap bmpOut;
MemoryStream msOut = new MemoryStream();
msOut.Write(buf, 0, buf.Length);
bmpOut = new Bitmap(msOut);
msOut.Close();
bmpOut.Save("ImageOut.bmp", System.Drawing.Imaging.ImageFormat.Bmp); //
ERROR: Throw the above exception !!!!
Can anybody tell what is the problem that causes the DGI error ?
Any help will be highly appreciated.