我有一個位圖...如果位圖的高度大於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