【发布时间】:2014-03-17 04:00:16
【问题描述】:
Android:设备 2.3.3 运行良好。但设备 4.3(HTC One)、4.2.2 不起作用。加载图片
'公共静态位图 getBitmapFroUrl(String url) {
URL m;
InputStream i = null;
BufferedInputStream bis = null;
ByteArrayOutputStream out =null;
try {
m = new URL(url);
URLConnection connection = m.openConnection();
try {
HttpURLConnection httpConnection = (HttpURLConnection) connection;
httpConnection.setRequestMethod("GET");
httpConnection.connect();
if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
i = httpConnection.getInputStream();
}
} catch (Exception ex) {
ex.printStackTrace();
}
bis = new BufferedInputStream(i,1024 * 8);
out = new ByteArrayOutputStream();
int len=0;
byte[] buffer = new byte[1024];
while((len = bis.read(buffer)) != -1){
out.write(buffer, 0, len);
}
byte[] data = out.toByteArray();
out.close();
bis.close();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds=true;
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length,options);
return bitmap;
} catch (Exception e) {
return null;
}
}'
我不知道为什么?请帮我。谢谢!
我知道:位图位图 = BitmapFactory.decodeByteArray(data, 0, data.length,options);
位图 = null (4.2.2, 4.3)
位图不为空(2.3.3)
【问题讨论】:
标签: android