Search code examples
c#bitmapimagestride256color

What is the stride for a 256 color (8 bit) bitmap?


There are lots of questions (and answers) here and elsewhere about calculating stride. I've got some bitmaps that I need to read into memory. Everything works fine IFF they are 16.5 million colors (24 bit). However, I only need them to be 256 color (8 bit) and when I tried to load in the exact image, but with a lower color depth, it blows up. I could just live with this; except that, obviously, a 256 color image is a lot smaller than a 16.5 million color image.

So, what is the stride for a 256 color gray scale (8 bit) image?


Solution

  • For a 8-bit image, the stride would just be the width in pixels. This is rounded up to the next multiple of 4. For example if the image is 198 pixels wide, the stride would be 200.