Reputation: 165
Is there any way to crop Drawable ImageView
in Android. When I searched in google I found lot of examples to crop camera image or gallery image, but i didn't find any solution for ImageView
and the source of that image is from my drawablefolder
.
Please anyone help me to crop drawable image.
Thanks in advance.
Upvotes: 1
Views: 10841
Reputation: 1560
<ImageView
android:src="@drawable/image"
android:adjustViewBounds="true"
android:scaleType="centerCrop" >
</ImageView>
Upvotes: 1
Reputation: 1107
Subclass the ImageView and override the onTouch method. Alternatively you can attach an onGestureDetector. Based on how you want it to behave use a matrix of transformation to scale or translate the image, loaded from your drawables. Finally enable the drawing cache of the view and use the getDrawingCache() method to obtain what you dynamically set for the ImageView to display.
Upvotes: 0
Reputation: 33258
You can use createBitmap
for crop and createScaledBitmap
for scale bitmap.
Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, width, height);
you can also scale image..
mBitmap = Bitmap.createScaledBitmap(mBitmap, width, height, true);
Upvotes: 3
Reputation: 1728
Have you tried to use createScaledBitmap? Take a look at this example https://stackoverflow.com/a/15789801/1342638
Upvotes: 0