Search code examples
androidbitmapdrawablesurfaceview

draw only a portion of a Drawable/Bitmap


I was wondering if it is possible to draw only a portion of a bitmap after it is loaded into memory without creating a new Bitmap. I see Drawable has a setBounds method but im not sure if it only draws the area set or just resizes the entire image. Thank you.


Solution

  • Assuming you have a main canvas to draw to, you can use one of the drawBitmap methods of the Canvas class to draw a subset of the loaded bitmap.

    public void drawBitmap (Bitmap bitmap, Rect src, Rect dst, Paint paint)