应用相机崩溃
Posted
技术标签:
【中文标题】应用相机崩溃【英文标题】:App camera crash 【发布时间】:2012-05-18 18:04:11 【问题描述】:我使用 developer.android.com 中的下一个教程: http://developer.android.com/training/camera/photobasics.html 使用 API 2.1
当我点击小图时,没问题 点进去拍小图,点进去拍大图,没问题 但是,当我直接点击大图时,我拍照并导致我的应用崩溃...在 LogCat 中:
05-10 09:26:30.773: D/CameraSample(3407): failed to create directory
05-10 09:26:33.713: W/IInputConnectionWrapper(3407): showStatusIcon on inactive InputConnection
05-10 09:26:45.883: I/Parcours(3407): handleBigCameraPhoto
05-10 09:26:46.133: D/dalvikvm(3407): GC_EXTERNAL_ALLOC freed 124K, 52% free 2628K/5379K, external 1685K/2133K, paused 207ms
05-10 09:26:46.143: E/dalvikvm-heap(3407): 31961088-byte external allocation too large for this process.
05-10 09:26:46.163: E/GraphicsJNI(3407): VM won't let us allocate 31961088 bytes
05-10 09:26:46.213: D/dalvikvm(3407): GC_FOR_MALLOC freed 2K, 52% free 2625K/5379K, external 1685K/2133K, paused 55ms
05-10 09:26:46.213: D/skia(3407): --- decoder->decode returned false
05-10 09:26:46.213: D/AndroidRuntime(3407): Shutting down VM
05-10 09:26:46.223: W/dalvikvm(3407): threadid=1: thread exiting with uncaught exception (group=0x4001d560)
05-10 09:26:46.223: E/AndroidRuntime(3407): FATAL EXCEPTION: main
05-10 09:26:46.223: E/AndroidRuntime(3407): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
05-10 09:26:46.223: E/AndroidRuntime(3407): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
05-10 09:26:46.223: E/AndroidRuntime(3407): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:470)
05-10 09:26:46.223: E/AndroidRuntime(3407): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:284)
05-10 09:26:46.223: E/AndroidRuntime(3407): at rdaquin.apps.takephoto.TakePhotoActivity.setPic(TakePhotoActivity.java:124)
05-10 09:26:46.223: E/AndroidRuntime(3407): at rdaquin.apps.takephoto.TakePhotoActivity.handleBigCameraPhoto(TakePhotoActivity.java:195)
05-10 09:26:46.223: E/AndroidRuntime(3407): at rdaquin.apps.takephoto.TakePhotoActivity.onActivityResult(TakePhotoActivity.java:281)
05-10 09:26:46.223: E/AndroidRuntime(3407): at android.app.Activity.dispatchActivityResult(Activity.java:3908)
05-10 09:26:46.223: E/AndroidRuntime(3407): at android.app.ActivityThread.deliverResults(ActivityThread.java:2549)
05-10 09:26:46.223: E/AndroidRuntime(3407): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2595)
05-10 09:26:46.223: E/AndroidRuntime(3407): at android.app.ActivityThread.access$2000(ActivityThread.java:121)
05-10 09:26:46.223: E/AndroidRuntime(3407): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:973)
05-10 09:26:46.223: E/AndroidRuntime(3407): at android.os.Handler.dispatchMessage(Handler.java:99)
05-10 09:26:46.223: E/AndroidRuntime(3407): at android.os.Looper.loop(Looper.java:123)
05-10 09:26:46.223: E/AndroidRuntime(3407): at android.app.ActivityThread.main(ActivityThread.java:3701)
05-10 09:26:46.223: E/AndroidRuntime(3407): at java.lang.reflect.Method.invokeNative(Native Method)
05-10 09:26:46.223: E/AndroidRuntime(3407): at java.lang.reflect.Method.invoke(Method.java:507)
05-10 09:26:46.223: E/AndroidRuntime(3407): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
05-10 09:26:46.223: E/AndroidRuntime(3407): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
05-10 09:26:46.223: E/AndroidRuntime(3407): at dalvik.system.NativeStart.main(Native Method)
如果你需要代码,问我。
我不明白为什么我的应用程序崩溃了,我觉得这是内存问题但我不知道该怎么办。 这样当我“拍一张小照片”和“拍一张大照片”时,它就可以工作了。但是如果我重新加载应用程序并且我“拍一张大图”不起作用
【问题讨论】:
【参考方案1】:我认为从堆栈跟踪中可以很明显地看出,由于您试图在堆上分配 32MB,因此内存不足。你不能那样做。这并不奇怪,因为当你拍一张大照片时会发生这种情况。你不能把它放在记忆中。将其写入存储。
【讨论】:
好的,但我有一个问题。为什么我拍小图,拍大图后就没有问题了。但是,当我重新启动我的应用程序并单独拍摄一张大照片时,我遇到了内存问题? 我找到了解决我的问题的方法,我需要在我的示例中更改 bmOptions.inSampleSize 我输入 5 并且没关系。你有计算 scaleFactor 的想法吗? 这是要求框架缩小图像。为什么不从较小的图像开始呢?更简单、更快。以上是关于应用相机崩溃的主要内容,如果未能解决你的问题,请参考以下文章