Getting java.lang.OutOfMemory Exception -- Bitmap
I know inSampleSize will help me to resolve my issue, but little bit confuse how it has to be use in my code.
Exception line:-
bMapRotate = Bitmap.createBitmap(tempBM, 0, 0, tempBM.getWidth(),
showPicture() method:
private void showPicture(){
if(pic!=null) tempBM = BitmapFactory.decodeFile(pic);
Bitmap bMapRotate;
Matrix matrix = new Matrix();
if(info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT){
float[] mirrorY = { -1, 0, 0, 0, 1, 0, 0, 0, 1};
Matrix matrixMirrorY = new Matrix();
matrixMirrorY.setValues(mirrorY);
matrix.postConcat(matrixMirrorY);
bMapRotate = Bitmap.createBitmap(tempBM, 0, 0, tempBM.getWidth(),
tempBM.getHeight(), matrix, true);
}
if(Utility.isTablet(this)) {
int orient = getResources().getConfiguration().orientation;
if(orient==1){
matrix.postRotate(90);
bMapRotate = Bitmap.createBitmap(tempBM, 0,0,tempBM.getWidth(),
tempBM.getHeight(), matrix ,true);
tempBM = bMapRotate;
}
}else{
//Get Orientation:
int orientation;
if(tempBM.getHeight() < tempBM.getWidth()){
orientation = 90;
} else {
orientation = 0;
}
if (orientation != 0) {
matrix.postRotate(orientation);
bMapRotate = Bitmap.createBitmap(tempBM, 0, 0, tempBM.getWidth(),
tempBM.getHeight(), matrix, true);
} else
bMapRotate = Bitmap.createScaledBitmap(tempBM, tempBM.getWidth(),
tempBM.getHeight(), true);
tempBM = bMapRotate;
}
Log:-
01-29 10:16:04.625: E/AndroidRuntime(20234): java.lang.OutOfMemoryError
01-29 10:16:04.625: E/AndroidRuntime(20234): at android.graphics.Bitmap.nativeCreate(Native Method)
01-29 10:16:04.625: E/AndroidRuntime(20234): at android.graphics.Bitmap.createBitmap(Bitmap.java:640)
01-29 10:16:04.625: E/AndroidRuntime(20234): at android.graphics.Bitmap.createBitmap(Bitmap.java:586)
01-29 10:16:04.625: E/AndroidRuntime(20234): at com.tanukiteam.camera.CameraAPIActivity.showPicture(CameraAPIActivity.java:685)
01-29 10:16:04.625: E/AndroidRuntime(20234): at com.tanukiteam.camera.CameraAPIActivity.access$1(CameraAPIActivity.java:650)
01-29 10:16:04.625: E/AndroidRuntime(20234): at com.tanukiteam.camera.CameraAPIActivity$1.onPictureTaken(CameraAPIActivity.java:539)
01-29 10:16:04.625: E/AndroidRuntime(20234): at android.hardware.Camera$EventHandler.handleMessage(Camera.java:789)
01-29 10:16:04.625: E/AndroidRuntime(20234): at android.os.Handler.dispatchMessage(Handler.java:99)
01-29 10:16:04.625: E/AndroidRuntime(20234): at android.os.Looper.loop(Looper.java:137)
01-29 10:16:04.625: E/AndroidRuntime(20234): at android.app.ActivityThread.main(ActivityThread.java:4921)
01-29 10:16:04.625: E/AndroidRuntime(20234): at java.lang.reflect.Method.invokeNative(Native Method)
01-29 10:16:04.625: E/AndroidRuntime(20234): at java.lang.reflect.Method.invoke(Method.java:511)
01-29 10:16:04.625: E/AndroidRuntime(20234): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1036)
01-29 10:16:04.625: E/AndroidRuntime(20234): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:803)
01-29 10:16:04.625: E/AndroidRuntime(20234): at dalvik.system.NativeStart.main(Native Method)