Hi, i am trying to use the code below to show a image from a file but on the line "Image image = Image.FromStream(mStream); " it gives me a parameter is invalid error and i do not know how to solve, any ideas
private Image getImage(byte[] inputImage)
{
byte[] header = new byte[] { 68, 68, 83, 32, 124, 0, 0, 0, 15, 16, 0, 0, 207, 0, 0, 0, 220, 0, 0, 0, 128, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 0, 0, 0, 0, 255, 8, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
MemoryStream mStream = new MemoryStream();
BinaryWriter bw = new BinaryWriter(mStream);
bw.BaseStream.Position = 0;
bw.Write(header);
bw.Write(inputImage);
Image image = Image.FromStream(mStream);
bw.Close();
return image;
}

Need Help! "Paramter is invalid"
Ronaldlee Ejalu
Hi,
if you do not have the headers for the image then you can use the Bitmap.LockBits to populate the pixel data, however you will need to know the size and format of the image data you are trying to populate to initialize the bitmap object.
Mark.
Andreia
or this:
http://msdn2.microsoft.com/en-US/library/system.drawing.bitmap.unlockbits.aspx
Rosetta
Hi,
see this thread: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1126715&SiteID=1 I give an example of how to create an image using the LockBits method.
Mark.
srinivas_kv80
IMBack
I've replicated your problem by unlocking the bits of a bitmap and marshalling them into a byte[].
The object browser in VS says "The stream does not have a valid image format-or-stream is null."
Are you sure the header is correct
RPKJBP
This should do it:
private Bitmap GetImage(byte[] inputImage, Size size, PixelFormat pixelFormat)< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
{
Bitmap bmp = new Bitmap(size.Width, size.Height);
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, pixelFormat);
IntPtr ptr = bmpData.Scan0;
int bytes = bmp.Width * bmp.Height * 3;
System.Runtime.InteropServices.Marshal.Copy(inputImage, 0, ptr, bytes);
bmp.UnlockBits(bmpData);
return bmp;
}
Bart Butell
DLdfrd
Nick Colebourn
Octopus384