0
朋友,java.lang.OutOfMemoryError:位图大小是否超出VM预算?
我正在使用以下代码在屏幕上显示位图并使用下一个和上一个按钮来更改图像。
并获得内存不足的错误
新代码
HttpGet httpRequest = null;
try {
httpRequest = new HttpGet(mImage_URL[val]);
} catch (Exception e) {
return 0;
}
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
Bitmap bm;
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
InputStream is = bufHttpEntity.getContent();
try
{
bm = BitmapFactory.decodeStream(is);
}catch(Exception ex)
{
}
is.close();
旧代码
URL aURL = new URL(mImage_URL[val]);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = null;
try
{
is= conn.getInputStream();
}catch(IOException e)
{
}
BufferedInputStream bis = new BufferedInputStream(is);
bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
img.setImageBitmap(bm);
,它是给我错误decoder->解码返回false。对尺寸大于400kb的图像提供
。
所以谷歌搜索后,我得到了新的代码作为回答 旧代码并没有给我这些图像的内存错误,但解码器 - >解码返回false,所以我选择了新的代码。
任何人指导我什么是解决方案,哪个是最好的方法来显示实时图像?
我会支持费奥多尔这个......怎么把这是他给我的解决方案创造了奇迹...尝试采样位图以减少记忆... – JaVadid 2010-06-15 07:36:00