我有一个位图...如果位图的高度大于maxHeight,或者宽度大于maxWidth,我想按比例调整图像的大小,使其适合maxWidth X最大高度。这里就是我想:按比例调整位图的大小
BitmapDrawable bmp = new BitmapDrawable(getResources(), PHOTO_PATH);
int width = bmp.getIntrinsicWidth();
int height = bmp.getIntrinsicHeight();
float ratio = (float)width/(float)height;
float scaleWidth = width;
float scaleHeight = height;
if((float)mMaxWidth/(float)mMaxHeight > ratio) {
scaleWidth = (float)mMaxHeight * ratio;
}
else {
scaleHeight = (float)mMaxWidth/ratio;
}
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap out = Bitmap.createBitmap(bmp.getBitmap(),
0, 0, width, height, matrix, true);
try {
out.compress(Bitmap.CompressFormat.JPEG, 100,
new FileOutputStream(PHOTO_PATH));
}
catch(FileNotFoundException fnfe) {
fnfe.printStackTrace();
}
我得到以下异常:
java.lang.IllegalArgumentException: bitmap size exceeds 32bits
什么我错在这里做什么?
你能在这里通过更正的代码吗?我得到同样的例外 – Mahesh 2012-12-12 07:07:45