I'm faced in a problem which i think is simple to solve, just i did something wrong, so: I have an Android tablet, where the user can draw signature, i get the image (.JPEG) by adb.
ProcessStartInfo adb_copy = new ProcessStartInfo("C:/SCR/adb/adb.exe");
adb_copy.Arguments = "pull \"mnt/sdcard/sign.jpg\" \"C:\\SCR\\temp\\sign.jpg\"";
adb_copy.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(adb_copy);
I have two Image variables:
Image WORKER_sign;
Image EMPLOYER_sign;
I load the image in these, and in a picturebox too:
using (FileStream stream = new FileStream("C:/SCR/temp/sign.jpg", FileMode.Open, FileAccess.Read))
{
WORKER_sign = Image.FromStream(stream);
stream.Close();
}
pictureBox3.Image = WORKER_sign;
pictureBox3.SizeMode = PictureBoxSizeMode.Zoom;
The picturebox shows the images perfectly, however i can't write in a byte array. I tried the following code:
public static byte[] ImageToByte(Image img)
{
if (img == null) return null;
byte[] result;
using (MemoryStream stream = new MemoryStream())
{
img.Save(stream, img.RawFormat);
result = stream.GetBuffer();
}
return result;
}
byte[] temparray = ImageToByte(WORKER_SIGN);
But the last line throws me a Generic GDI+ exception, and before this the IntelliTrace shows some System.ObjectDisposedException ("Closed file") too.
What's wrong with my code? Thank you for all the help! :)
OFF: Sorry for my bad ENG...
EDIT: The errors:
Exception:Thrown: "Cannot access a closed Stream." (System.ObjectDisposedException) A System.ObjectDisposedException was thrown: "Cannot access a closed Stream." Time: 2014.08.11. 14:37:49 Thread:Main Thread[7276]
Exception:Thrown: "Generic error in: GDI+." (System.Runtime.InteropServices.ExternalException) A System.Runtime.InteropServices.ExternalException was thrown: "Generic error in: GDI+." Time: 2014.08.11. 14:37:49 Thread:Main Thread[7276]