Jump to content
  • Advertisement
Sign in to follow this  
Giawa

MemoryStream Image without header

This topic is 3715 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
Advertisement
Use Bitmap.LockBits to get the underlying bitmap data, and then persist that to a stream.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!