Bitmap bmp, rotated;
InputStream stream = context.getContentResolver().openInputStream(uri);
bmp = BitmapFactory.decodeStream(stream); // stream does not equal null
Matrix mat = new Matrix();
mat.postScale(0.5f, 0.5f);
mat.postRotate((float)rotation);
// rotation calculated using ExifInterface orientation attr. for example: 90
rotated = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), mat, true);
使用上面的代码片段,有时 bmp == null 并且我得到 NullPointerException @ Bitmap.createBitmap ...我从相机活动中获取 uri .. 图像肯定会被保存。
如果这是问题,我会得到 OutOfMemoryException 吗?有没有人认为这有什么问题或改进它的方法?