Sign in to follow this  

MemoryStream Image without header

This topic is 3351 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm trying to write a System.Drawing.Image into a MemoryStream without the header information. I only want to byte array that makes up the pixel data. Does anyone know of a way to do this? Right now I have to save the image into a MemoryStream and then copy that memory stream to a new byte array with a 54 byte offset.
            Image t_image = Image.FromFile(ResourceFile);
            MemoryStream t_ms = new MemoryStream();
            t_image.Save(t_ms, System.Drawing.Imaging.ImageFormat.Bmp);
            byte[] t_byte = new byte[t_ms.Length - 54];
            t_ms.Position = 54;
            t_ms.Read(t_byte, 0, (int)t_ms.Length - 54);
That's how I'm accomplishing it right now. I know that the bmp header is 54 bytes. Thanks, Giawa

Share this post


Link to post
Share on other sites
I got it working, but something weird is happening. The image is being flipped on the y-axis. Any ideas of why this is happening? I can fix it with RotateFlip(RotateFlipType.RotateNoneFlipY); but I'd prefer to find out why it is happening in the first place. Thanks!


Image t_bitmap = Bitmap.FromFile(ResourceFile);
t_bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
System.Drawing.Imaging.BitmapData t_data = ((Bitmap)t_bitmap).LockBits(new Rectangle(0, 0, t_bitmap.Width, t_bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, t_bitmap.PixelFormat);


Giawa

Share this post


Link to post
Share on other sites

This topic is 3351 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this