【发布时间】:2015-08-07 11:39:03
【问题描述】:
我正在尝试压缩位图,但得到一个空指针异常..logcat 显示未捕获的异常
Bitmap bitmap = BitmapFactory.decodeByteArray(imageAsBytes , 0, imageAsBytes .length);
Bitmap bPNGcompress =codec(bitmap, Bitmap.CompressFormat.PNG, 0);
Bitmap scaled = bPNGcompress.createScaledBitmap( bPNGcompress, 100, 100, true );
方法实现
private static Bitmap codec(Bitmap map, Bitmap.CompressFormat format,
int quality) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
map.compress(format, quality, os);
try {
os.flush();
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
byte[] array = os.toByteArray();
return BitmapFactory.decodeByteArray(array, 0, array.length);
}
【问题讨论】:
标签: android bitmap android-bitmap bitmapfactory