当我从浏览器打开php文件时:" http://192.168.1.30/save/load_image_from_db.php?id=" + id; 图像显示正确,但当我尝试从Android应用程序显示它不起作用,我得到此错误:skimageDecoder :: Factory返回null。
Bitmap对象仍然为null,即使我为它分配了我从url.opencnnection()得到的streamStream。getStream()!
代码:
@Override
protected Bitmap doInBackground(String... params) {
String id = params[0];
String add = "http://192.168.1.30/save/load_image_from_db.php?id="+id;
URL url;
Bitmap image = null;
try {
url = new URL(add);
InputStream is = url.openConnection().getInputStream();
image = BitmapFactory.decodeStream(is);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return image;
}
}
答案 0 :(得分:0)
试试这个:
@Override
protected Bitmap doInBackground(String... params) {
String id = params[0];
String add = "http://192.168.1.30/save/load_image_from_db.php?id="+id;
Bitmap image = null;
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(add);
HttpResponse response;
try {
response = (HttpResponse)client.execute(request);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufferedEntity = new BufferedHttpEntity(entity);
InputStream inputStream = bufferedEntity.getContent();
image = BitmapFactory.decodeStream(inputStream);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return image;
}
希望它有所帮助。