1

第一次,没有问题,它工作正常。但是当我再次点击“拍照”时,应用程序崩溃了。这是我的代码:

ImageView myImage = (ImageView)findViewById(R.id.ivReturnPic);
Bitmap = bmap = BitmapFactory.decodeFile(file.getAbsolutePath());
myImage.setImageDrawable(bmap);

这是logcat信息:

08-09 10:06:23.835: E/AndroidRuntime(28492): FATAL EXCEPTION: main
08-09 10:06:23.835: E/AndroidRuntime(28492): java.lang.OutOfMemoryError
08-09 10:06:23.835: E/AndroidRuntime(28492):    at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
08-09 10:06:23.835: E/AndroidRuntime(28492):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:650)
08-09 10:06:23.835: E/AndroidRuntime(28492):    at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:389)
08-09 10:06:23.835: E/AndroidRuntime(28492):    at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:449)
08-09 10:06:23.835: E/AndroidRuntime(28492):    at com.example.customcalenderandroid.Camera.onActivityResult(Camera.java:232)
08-09 10:06:23.835: E/AndroidRuntime(28492):    at android.app.Activity.dispatchActivityResult(Activity.java:5390)
08-09 10:06:23.835: E/AndroidRuntime(28492):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3178)
08-09 10:06:23.835: E/AndroidRuntime(28492):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3225)
08-09 10:06:23.835: E/AndroidRuntime(28492):    at android.app.ActivityThread.access$1100(ActivityThread.java:140)
08-09 10:06:23.835: E/AndroidRuntime(28492):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1275)
08-09 10:06:23.835: E/AndroidRuntime(28492):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-09 10:06:23.835: E/AndroidRuntime(28492):    at android.os.Looper.loop(Looper.java:137)
08-09 10:06:23.835: E/AndroidRuntime(28492):    at android.app.ActivityThread.main(ActivityThread.java:4898)
08-09 10:06:23.835: E/AndroidRuntime(28492):    at java.lang.reflect.Method.invokeNative(Native Method)
08-09 10:06:23.835: E/AndroidRuntime(28492):    at java.lang.reflect.Method.invoke(Method.java:511)
08-09 10:06:23.835: E/AndroidRuntime(28492):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
08-09 10:06:23.835: E/AndroidRuntime(28492):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
08-09 10:06:23.835: E/AndroidRuntime(28492):    at dalvik.system.NativeStart.main(Native Method)
08-09 10:06:23.840: E/android.os.Debug(2401): !@Dumpstate > dumpstate -k -t -z -d -o /data/log/dumpstate_app_error
4

1 回答 1

1

您得到的异常是 OutOfMemoryException。顾名思义,这意味着您的应用程序内存不足。在 Android 中处理图像有时会有点棘手,尤其是当您拍摄全尺寸照片时。没有多少智能手机,即使是高端智能手机,可以同时处理一个以上的全尺寸位图。使用 bitmap.recycle() 尽快回收不需要的位图可以解决很多问题。在这里您可以找到有关以内存友好的方式加载位图的更多信息:http: //developer.android.com/training/camera/photobasics.html#TaskScalePhoto

于 2013-08-09T16:26:04.117 回答