سؤال

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?

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

The stride of an 8bit image is equal to the width of the image.

The stride will depend on the color format used. To get the stride value, you multiply the number of bytes used by pixel by the width of the image.

There is nothing actually defining what the stride should be. Generally, as said, it is the width rounded up to the next multiple of four, but there is nothing actually enforcing that as standard.

The only way to be completely sure is just to request it from the image. No information was given about how you access the image data, but the standard way to do so is to create a Bitmap object of your image, and use the bitmap.LockBits function to get a BitmapData object. In that case, Stride is simply a property of that BitmapData object.

If you somehow already have the actual image data as byte array, you can just divide it by the height, of course.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top