I have a little problem to convert byte array to Bitmap. Here is my exception:
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
My code:
public static System.Drawing.Bitmap ByteToImage(byte[] data)
{
System.Drawing.Bitmap bmp;
using (var ms = new MemoryStream(data))
{
bmp = new System.Drawing.Bitmap(ms);
}
return bmp;
}
Bitmap b = ByteToImage(editor1.system.Tiles[0].ImageData);
Form f = new Form();
f.BackgroundImage = b;
f.Show();
I need to load a serialized byte array on the list and convert to an image at runtime.
If I save the bitmap
b.Save(@"C:\test.png");
It works if I try to load bitmap at runtime I get this error.