I'm trying to show a certain part of an image.
For example:
I tried to set a ClipDrawable
of an ImageView
from a Bitmap
using the code below, but it didn't show up.
BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
ClipDrawable clipDrawable = new ClipDrawable(bitmapDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
clipDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
clipDrawable.setLevel(5000);
imageView.setImageDrawable(clipDrawable);
I also tested to make sure the problem wasn't with the BitmapDrawable
by seeing if imageView.setImageDrawable(bitmapDrawable)
would show the full image and it did display it correctly.
How can I show a fraction of a Bitmap
using ClipDrawable
?
Why is the image not showing up?
I looked at this post, but the accepted answer assumes that the image can be retrieved from the resources whereas I'm loading my image dynamically.
The answers to the post android - How to cut some part of image and show it in imageview don't answer my question using ClipDrawable
and just use magic numbers to create a new Bitmap
.
The Android docs on ClipDrawable
only explain how to solve this problem if you set the Drawable
in XML.