Android skimageDecoder::Factory returned null



当我从浏览器打开php文件时:"http://192.168.1.30/save/load_image_from_db.php?id="+id;图像显示正确,但是当我尝试从Android应用程序显示它时,它不起作用,并且出现此错误:skimage解码器::工厂返回null。

位图对象仍然为空,即使我分配给它解码流,我从url.opencnnection().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;
            }
        }

试试这个:

@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;
}

希望对您有所帮助。

相关内容

最新更新