【发布时间】:2010-06-15 07:10:00
【问题描述】:
朋友们,
我正在使用以下代码在屏幕上显示位图,并使用下一个和上一个按钮来更改图像。
内存不足错误
新代码
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);
它给了我错误解码器->解码返回错误。
在大小大于 400kb 的图像上。
所以在谷歌搜索后我得到了新代码作为答案 旧代码在这些图像上没有给我内存不足错误,但解码器->解码返回 false,所以我选择了新代码。
任何人指导我什么是解决方案,哪种是显示实时图像的最佳方法?
【问题讨论】:
标签: android