I am new to Android and I have two images one is an empty image and the other is a full image to represent a progress bar.
How can I only draw a percentage of the full image using canvas.drawBitmap?
I would prefer not to resize the bitmap image each time.
you can use 2 Rects, the source Rect and the destination Rect to only draw a piece
//example
bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.backbutton);
Rect source = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
Rect bitmapRect = new Rect(0, 0, canvasWidth -200,50);
canvas.drawBitmap(bitmap, source, bitmapRect, null);
a Rect is a rectangle like this
new Rect(topleftx,toplefty,bottomrightx,bottomrighty);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With