Reputation: 573
When i rotate my large bitmap using matrix so application crash,i don't want to using canvas. i am using below code,please help me Thanks
Matrix mMatrix = new Matrix();
rotateRight.postRotate(90);
rotateBitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
bm.getHeight(), rotateRight, true);
See below logcate
java.lang.OutOfMemoryError
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:924)
at android.graphics.Bitmap.createBitmap(Bitmap.java:901)
at android.graphics.Bitmap.createBitmap(Bitmap.java:833)
at com.insta.fragment.HomeFragment.rotateBitmap(HomeFragment.java:1363)
at com.insta.fragment.HomeFragment.getBitmap(HomeFragment.java:1376)
at com.insta.customcontrol.CameraPreview$3.onPictureTaken(CameraPreview.java:447)
at android.hardware.Camera$EventHandler.handleMessage(Camera.java:998)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5586)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Upvotes: 0
Views: 361
Reputation: 10856
I think you need to set options for that
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(data , 0, data .length,options);
more explanations at docs
OR try with below code
try {
//Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(data , 0, data .length,o);
//The new size we want to scale to
final int REQUIRED_WIDTH=WIDTH;
final int REQUIRED_HIGHT=HIGHT;
//Find the correct scale value. It should be the power of 2.
int scale=1;
while(o.outWidth/scale/2>=REQUIRED_WIDTH && o.outHeight/scale/2>=REQUIRED_HIGHT)
scale*=2;
//Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize=scale;
Bitmap finalBitmap = BitmapFactory.decodeByteArray(data , 0, data .length,o2);
}
catch (Exception e) {
}
Upvotes: 1