我有处理相机的片段。我的问题是它拍了一张照片并将其显示在 imageView 上,就好了。
我第二次尝试拍照时出现 OutOfMemory 错误。任何提示如何在第一张照片后释放内存?
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
System.out.println("tesstssaffsafdfsdfsd");
switch (requestCode) {
case TAKE_PICTURE:
if (resultCode == Activity.RESULT_OK) {
getActivity().getContentResolver().notifyChange(mUri, null);
ContentResolver cr = getActivity().getContentResolver();
try {
mPhoto = android.provider.MediaStore.Images.Media.getBitmap(cr, mUri);
((ImageView)rootView.findViewById(R.id.snap)).setImageBitmap(mPhoto);
} catch (Exception e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
}
这是堆栈跟踪:
08-21 16:33:27.450: E/AndroidRuntime(1840): FATAL EXCEPTION: main
08-21 16:33:27.450: E/AndroidRuntime(1840): java.lang.OutOfMemoryError
08-21 16:33:27.450: E/AndroidRuntime(1840): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
08-21 16:33:27.450: E/AndroidRuntime(1840): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:650)
08-21 16:33:27.450: E/AndroidRuntime(1840): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:722)
08-21 16:33:27.450: E/AndroidRuntime(1840): at android.provider.MediaStore$Images$Media.getBitmap(MediaStore.java:790)
08-21 16:33:27.450: E/AndroidRuntime(1840): at com.example.lemonrelative.reading.AddReadingFrag_3.onActivityResult(AddReadingFrag_3.java:113)
08-21 16:33:27.450: E/AndroidRuntime(1840): at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:166)
08-21 16:33:27.450: E/AndroidRuntime(1840): at android.app.Activity.dispatchActivityResult(Activity.java:5390)
08-21 16:33:27.450: E/AndroidRuntime(1840): at android.app.ActivityThread.deliverResults(ActivityThread.java:3178)
08-21 16:33:27.450: E/AndroidRuntime(1840): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3225)
08-21 16:33:27.450: E/AndroidRuntime(1840): at android.app.ActivityThread.access$1100(ActivityThread.java:140)
08-21 16:33:27.450: E/AndroidRuntime(1840): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1275)
08-21 16:33:27.450: E/AndroidRuntime(1840): at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 16:33:27.450: E/AndroidRuntime(1840): at android.os.Looper.loop(Looper.java:137)
08-21 16:33:27.450: E/AndroidRuntime(1840): at android.app.ActivityThread.main(ActivityThread.java:4898)
08-21 16:33:27.450: E/AndroidRuntime(1840): at java.lang.reflect.Method.invokeNative(Native Method)
08-21 16:33:27.450: E/AndroidRuntime(1840): at java.lang.reflect.Method.invoke(Method.java:511)
08-21 16:33:27.450: E/AndroidRuntime(1840): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
08-21 16:33:27.450: E/AndroidRuntime(1840): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
08-21 16:33:27.450: E/AndroidRuntime(1840): at dalvik.system.NativeStart.main(Native Method)