내가 메모리 오류 벗어나 려하고있다 : 아래 - BitmapFactory.decodeStream
내 코드입니다 :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);
I에서 오류가 발생하고 이 오류가 발생합니다 Out of memory on a 3250016-byte allocation.
나는 많은 게시물을 보았지만 여전히 soluti를 찾을 수 없습니다. 이 경우에.
어떤 오류가 발생합니까? LogCat 또는 StackTrace를 붙여주십시오. –
먼저 메모리에 스트림을로드하는 이유는 무엇입니까? 서버 또는 로컬 파일에서 이미지를 가져 오는 위치부터? – Triode
나는 데이터라는 폴더가있다. 나는 입력 스트림을 반환하는 클래스 로더를 사용하여 imges를 얻고 있는데, 나는이 메소드에 전달하고있다. – Goofy