java.lang.OutOfMemoryError [英] java.lang.OutOfMemoryError

查看:122
本文介绍了java.lang.OutOfMemoryError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拿相机的图像是一个保存在SD卡,存储图像必须从SD卡上传到一个这样的ImageView的:

I take an image with camera an store it in the sd card, the image stored must be upload from sd card to an imageView like that:

myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
ImageView _image=(ImageView)view.findViewById(R.id.imageCarte);
_image.setImageBitmap(myBitmap);

但我有此错误:

but i have this error:

8月5日至5日:23:20.593:E / AndroidRuntime(1936年):产生的原因:   java.lang.OutOfMemoryError:位图大小超过VM预算

05-05 08:23:20.593: E/AndroidRuntime(1936): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget.

谁能帮助我。谢谢

推荐答案

在移动使用BitmapFactory是内存耗时的过程。当你试图不断去codeA大量的图片会出现此问题。 在Java中没有选择释放分配给变量MYBITMAP的记忆。因此,确保这些类型的变量使用后都设置为null。

Using BitmapFactory in mobile is a memory consuming process. This problem will arise when you are trying to decode a lot of images continuously. As in java there is no option to free the memory allocated to the variable " myBitmap ". So make sure that these types of variables are set to null after using it.

也可以尝试使用

System.gc() to clear the garbage collection.

如果在执行一个错误被抛出_image.setImageBitmap(MYBITMAP);行再尝试显示之前,缩小图像尺寸

If an error is thrown while executing "_image.setImageBitmap(myBitmap);" line then try to reduce the image size before displaying

这篇关于java.lang.OutOfMemoryError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆