Skip to content Skip to sidebar Skip to footer

Illegalargumentexception: X + Width Must Be <= Bitmap.width() In Android

I want to crop an image with in a margin (10,50,10,50),(left,top,right,bottom) respectively of an imageview. Here is my code Bitmap bitmap = Bitmap.createBitmap(imgView.getWidth(

Solution 1:

try this and see if it works:

// using this method createBitmap(source, x, y, width, height)Bitmapresult= Bitmap.createBitmap(bitmap, 10,
            50, imgView.getWidth() - 20, imgView.getHeight() - 100);

getLeft and others is used to get the position of the view in its parent. Not the dimension of the bitmap.

Solution 2:

BitmapresultBitmap= Bitmap.createBitmap(sourceBitmap, 0, 0,
            sourceBitmap.getWidth() - 1, sourceBitmap.getHeight() - 1);

Like in lists, it starts from 0, so width must be bitmap width - 1.

Post a Comment for "Illegalargumentexception: X + Width Must Be <= Bitmap.width() In Android"