退房Android的位图内存不足的错误 [英] Out of memory error in android bitmap

查看:132
本文介绍了退房Android的位图内存不足的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是位图。它抛出内存不足的错误(2出5倍)的。
它如何能够避免。
搜索结果以下是我的code

  =位android.provider.MediaStore.Images.Media.getBitmap(CR,imageUri);
  photo_new = rotateImage(位图,90);
  ByteArrayOutputStream流=新ByteArrayOutputStream();  photo_new.com preSS(Bitmap.Com pressFormat.JPEG,100,流);
  字节[]的字节数组= stream.toByteArray();  意图I =新意图(getApplicationContext(),new_class.class);
  i.putExtra(形象,字节);  startActivity(ⅰ);
  的字节数组= NULL;


解决方案

您也越来越的 OutOfMemoryError异常因为你没有回收
那些位图您使用

尝试回收位图你用过之后它们

  =位android.provider.MediaStore.Images.Media.getBitmap(CR,imageUri);
  photo_new = rotateImage(位图,90);
  ByteArrayOutputStream流=新ByteArrayOutputStream();  photo_new.com preSS(Bitmap.Com pressFormat.JPEG,100,流);
  字节[]的字节数组= stream.toByteArray();
  bitmap.recycle();
  意图I =新意图(getApplicationContext(),new_class.class);
  i.putExtra(形象,字节);  startActivity(ⅰ);
  的字节数组= NULL;

I am using a bitmap. It throws out of memory error (2 out of 5 times). How can it be avoided.

Following is my code:

  bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, imageUri);
  photo_new= rotateImage(bitmap, 90);
  ByteArrayOutputStream stream = new ByteArrayOutputStream();

  photo_new.compress(Bitmap.CompressFormat.JPEG, 100, stream);
  byte[] byteArray = stream.toByteArray();

  Intent i = new Intent(getApplicationContext(),new_class.class);
  i.putExtra("image", byteArray);

  startActivity(i);
  byteArray=null;

解决方案

You are getting OutOfMemoryError because you haven't recycle those bitmaps you used

try to recycle those bitmaps after you used them

bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, imageUri);
  photo_new= rotateImage(bitmap, 90);
  ByteArrayOutputStream stream = new ByteArrayOutputStream();

  photo_new.compress(Bitmap.CompressFormat.JPEG, 100, stream);
  byte[] byteArray = stream.toByteArray();
  bitmap.recycle();
  Intent i = new Intent(getApplicationContext(),new_class.class);
  i.putExtra("image", byteArray);

  startActivity(i);
  byteArray=null;

这篇关于退房Android的位图内存不足的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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