I have an android app that allows users to take photos. In that effort, the image is not always correctly displayed, depending on the phone’s orientation during image capture. I have provided a rotate image feature that works on most, but not all phones. In fact, when it does not work the app crashes. The rotate feature is provided below. I appreciate any feedback that can get this to work on all phones. Also, the app just crashes and the error trap is not invoked.
private void rotateImage(float degrees){
try{
String imageFile = Environment.getExternalStorageDirectory()+"/"+Imagefile;
Bitmap bitmap = BitmapFactory.decodeFile(imageFile);
int width = bitmap.getWidth();
int height = bitmap.getHeight();
// resize the bit map
//matrix.postScale(scaleWidth, scaleHeight);
// rotate the Bitmap
Matrix matrix = new Matrix();
matrix.postRotate(degrees);
// create the new Bitmap
Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
imageAsset.setImageBitmap(rotatedBitmap);
// clean up
bitmap = null;
rotatedBitmap = null;
matrix = null;
}catch(Exception e){
utility.logError(this,"{"+CLASS_NAME+"}[rotateImage] Error: "+e.getMessage());
}
}
Probably put of memory error. The available heap depends on the type of phone. Even though the bitmaps are stored in native memory (which makes their memory consuption harder to track) they are limited to the same heap size. Big bitmaps (from a 5MP) camera easily use up all the memory in an app.
You would have to post your error log to be sure though.
For starters:
– use smaller images
Edit:
ok, thinking about it im pretty sure it’s the out-of-memory. That’s why the error doesn’t get caught, because it happens in native code.
This is what you do:
When you decode your image resample it to a smaller size: