Skip to main content
GameDev.net gamedev.net
🔒 Locked

MemoryStream Image without header

Started by Giawa Oct 10, 2008 at 12:50 AM 1 replies 1.4k views
Original Post
Giawa
Giawa
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
mutex
mutex
Use Bitmap.LockBits to get the underlying bitmap data, and then persist that to a stream.

Giawa
Giawa
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.