Android SkImageDecoder::Factory 返回 null 错误 [英] Android SkImageDecoder::Factory returned null Error

查看:14
本文介绍了Android SkImageDecoder::Factory 返回 null 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将图像从 URL 加载到 ImageView,但出现错误:SkImageDecoder::Factory 返回 null.我该如何解决?

I'm trying to load an image from URL to an ImageView but the error occurs: SkImageDecoder::Factory returned null. How can I fix it?

这是我的代码:

private class LoadImageFromURL extends AsyncTask<String, Void, Bitmap>{
        ImageView bitmapImgView;
        public LoadImageFromURL(ImageView bmImgView){
            bitmapImgView = bmImgView;
        }

        @Override
        protected Bitmap doInBackground(String... params) {
            // TODO Auto-generated method stub
            String urlStr = params[0];
            Bitmap img = null;
            try {
                URL url = new URL(urlStr);
                InputStream inputStream = url.openConnection().getInputStream();
                //Options bmFactoryOpt = new Options();
                //bmFactoryOpt.inJustDecodeBounds = false;
                img = BitmapFactory.decodeStream(inputStream);          
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }       
            return img;
        }

        @Override
        protected void onPostExecute(Bitmap bitmap){
            bitmapImgView.setImageBitmap(bitmap);
        }
    }

推荐答案

已解决.把代码改成这样.

Solved. Change the code to this.

@Override
        protected Bitmap doInBackground(String... params) {
            // TODO Auto-generated method stub
            String urlStr = params[0];
            Bitmap img = null;

            HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet(urlStr);
            HttpResponse response;
            try {
                response = (HttpResponse)client.execute(request);           
                HttpEntity entity = response.getEntity();
                BufferedHttpEntity bufferedEntity = new BufferedHttpEntity(entity);
                InputStream inputStream = bufferedEntity.getContent();
                img = BitmapFactory.decodeStream(inputStream);
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return img;
        }

这篇关于Android SkImageDecoder::Factory 返回 null 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆