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

13,065

Solution 1

In most cases the stride is the same as the width. The stride is useful if you are trying to copy/draw a sub-region of a Bitmap. For instance, if you have a 100x100 bitmap and you want to draw the 50x50 top-right corner, you can use a width of 50px and a stride of 100px.

Solution 2

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.

Share:
13,065
bigstones
Author by

bigstones

StackOverflow - Always been taking from the community (mostly googling), now trying to be part of it and contribute if, by chance, I know something that can help. Bicycles - All mountain biker on a Canyon Nerve AM. User Experience - When I've found this site, I had to sign up.

Updated on June 03, 2022

Comments

  • bigstones
    bigstones about 2 years

    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?

  • Zar E Ahmer
    Zar E Ahmer about 9 years
    Can you explain a little bit more with example.plz