[英]Android skimageDecoder::Factory returned null
當我從瀏覽器打開php文件時:“ http://192.168.1.30/save/load_image_from_db.php?id= ” + id; 圖像顯示正確,但是當我嘗試從android應用程序顯示圖像時,它不起作用,並且出現此錯誤:skimageDecoder :: Factory返回null。
即使我將其分配給從url.opencnnection()。getStream()獲得的流的解碼流,Bitmap對象仍然為null!
代碼:
@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;
}
}
嘗試這個 :
@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;
}
希望能幫助到你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.