异常信息:Caused by: java.lang.IllegalArgumentException: width and height must be > 0
异常代码:
Bitmap resizeBitmap(int desHeight, int desWidth, Bitmap originBitmap) {
int height = originBitmap.getHeight();
int width = originBitmap.getWidth();
Log.d("bitmap", "height = " + originBitmap.getHeight() + " width = "
+ originBitmap.getWidth());
float scale_y = desHeight / height;
float scale_x = desWidth / width;
Matrix matrix = new Matrix();
matrix.setScale(scale_x, scale_y);
Bitmap desBitmap = Bitmap.createBitmap(originBitmap, 0, 0, width,//此处出现异常
height, matrix, true);
Log.d("bitmap", "height = " + desBitmap.getHeight() + " width = "
+ desBitmap.getWidth());
return desBitmap;
}
解决方案:
float scale_y = desHeight / height; float scale_x = desWidth / width;//此处添加代码 if(height>desHeight && width >desWidth){ scale_y = height/desHeight; scale_x = width/desWidth; }