当我使用矩阵旋转我的大位图以便应用程序崩溃时,我不想使用画布。 我使用下面的代码,请帮助我谢谢
Matrix mMatrix = new Matrix();
rotateRight.postRotate(90);
rotateBitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
bm.getHeight(), rotateRight, true);
见下面的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)
答案 0 :(得分:1)
我认为您需要为此设置options
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(data , 0, data .length,options);
的更多解释
或尝试使用以下代码
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) {
}