我的内存不足错误:
下面是我的代码:
public static Bitmap decodeSampledBitmapFromResource(InputStream inputStream,int reqWidth, int reqHeight) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
try {
while ((len = inputStream.read(buffer)) > -1 ) {
baos.write(buffer, 0, len);
}
baos.flush();
InputStream is1 = new ByteArrayInputStream(baos.toByteArray());
InputStream is2 = new ByteArrayInputStream(baos.toByteArray());
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inDither=false;
options.inPurgeable=true;
options.inInputShareable=true;
options.inJustDecodeBounds = true;
// BitmapFactory.decodeResource(res, resId, options);
BitmapFactory.decodeStream(is1,null,options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeStream(is2,null,options); // error at this line
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
我在这一行遇到错误
BitmapFactory.decodeStream(is2,null,options);
我收到这个错误Out of memory on a 3250016-byte allocation.
我看过很多关于此的帖子,但在这种情况下仍然无法找到解决方案。