我创建了一个 Android 应用程序,它从图库中选择一张图片并显示预览。
@Override
public void onClick(View v) {
if (v.getId()== R.id.button){
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_PICK);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), SELECT_PICTURE);
}
选择图像后,应显示预览。
然而,它只是第一次起作用。稍后当我单击返回时,它显示 outOfMemoryException
最佳答案
在 android 中使用位图会消耗大量内存,由于内存泄漏,这需要引起高度重视。
你可以随时使用
System.gc()
进行垃圾收集并释放一些内存。
或
bitmap.recycle();
查看我在开发图像编辑应用程序时使用的这些博客文章。
关于java - 使用位图Android的内存不足错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18334117/