drawBitmap() and setPixels(): what's the stride?

bigstones picture bigstones · Jan 25, 2011 · Viewed 12.5k times · Source

Could please somebody explain me (ASCII is really welcome) what the stride argument stands for in Canvas.drawBitmap() and in Bitmap.setPixels()/getPixels()? I understand it's a way to skip elements in the colors array, but how?

Answer

Hoshin picture Hoshin · Jan 27, 2011

Stride is number of bytes used for storing one image row.

Stride can be different from the image width.

Most of the images are 4 byte aligned.

For ex. a 24 bit (RGB) image with width of 50 pixels. The total bytes required will be 150 (3(RGB)*50). As image will be 4 byte aligned, in this case the byte required will become 152.

So you will see stride as 152, width 50 and image alignment as 4 byte.