Search code examples
androidcanvasbitmapdrawing

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


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?


Solution

  • 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.