gpt4 book ai didi

android - 当一张照片被拍摄两次并在 ImageView 中显示图像时,应用程序崩溃

转载 作者:行者123 更新时间:2023-11-30 03:26:29 25 4
gpt4 key购买 nike

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

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

最佳答案

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

关于android - 当一张照片被拍摄两次并在 ImageView 中显示图像时,应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18149992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com