我正在研究相机应用程序.第一次,如果我捕获图像其工作正常,但如果我再次拍照,它会抛出一个错误
ERROR/dalvikvm-heap(2398):10077696字节的外部分配对于这个过程来说太大了."VM不会让我们分配10077696字节",最后是"05-02 05:35:38.390:ERROR/AndroidRuntime(2398):致命异常:主05-02 05:35:38.390:错误/ AndroidRuntime(2398):java.lang.OutOfMemoryError:位图大小超过VM预算
和应用程序强制关闭..如何处理这个如何清除堆和虚拟机?请帮忙..在此先感谢..
我找到了答案。
我使用了以下代码:
BitmapFactory.Options bfOptions=new BitmapFactory.Options();
bfOptions.inDither=false; //Disable Dithering mode
bfOptions.inPurgeable=true; //Tell to gc that whether it needs free memory, the Bitmap can be cleared
bfOptions.inInputShareable=true; //Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future
bfOptions.inTempStorage=new byte[32 * 1024];
CameraTricks.SdCardImage= BitmapFactory.decodeFile(CameraTricks.yu,bfOptions);
CameraTricks.yu is my path to bitmap
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7463 次 |
| 最近记录: |