user1083266
user1083266

Reputation: 1801

how to crop top,left,right and bottom portion of imageview in android

In my application i am getting transparent pixels in my Imageview while taking screenshot.How to cut top,left,rightenter image description here and bottom portion of Imageview.I tried below code but not working

Bitmap bitmap = Bitmap.createBitmap(imgView.getWidth(),imgView.getHeight(),                   Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
imgView.draw(canvas);
Bitmap result =Bitmap.createBitmap(bitmap,imgView.getLeft()+10, imgView.getTop()+50,    imgView.getWidth()-20, imgView.getHeight()-100);
 bitmap.recycle();

please help me to solve this issue.

enter image description here

Upvotes: 2

Views: 2748

Answers (1)

Chor Wai Chun
Chor Wai Chun

Reputation: 3236

I am not very sure what are you referring with "not working", but from first sight I would suggest you to change from

Bitmap result =Bitmap.createBitmap(bitmap,imgView.getLeft()+10, imgView.getTop()+50,    imgView.getWidth()-20, imgView.getHeight()-100);

to

Bitmap result =Bitmap.createBitmap(bitmap, 10, 50, bitmap.getWidth()-20, bitmap.getHeight()-100);

But I would not recommend you to use this kind of approach which explicitly setting width and height value.

Upvotes: 1

Related Questions