我正在使用位图。它抛出内存不足错误(5 次中有 2 次)。
怎么避免呢。
以下是我的代码:
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;
最佳答案
你得到 OutOfMemoryError因为你没有回收
您使用的那些位图
尝试回收
那些位图
在你使用它们之后
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;
关于java - android位图中的内存不足错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24203985/