Android SkImageDecoder::Factory 返回空错误

标签 android image bitmap

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

这是我的代码:

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

最佳答案

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

@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 返回空错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23559736/

相关文章:

java - 安卓 native Activity 。如何在其他线程中做一些工作?

javascript - 计算图像的点击偏移量

Android:上传位图而不先将它们保存到文件系统

php - 将位图图像转换为字节数组并存储到Mysql中

c# - 使用 webClient 保存网络驱动器照片

android - 对齐 Liniar 布局子项

android - 将 Android Gradle 插件更新到 3.2.0 或更高版本/生成 Flutter 签名的 APK

javascript - 模板化时存储和访问图像文件路径(来自 cloudinary 或其他服务)

git push 后图像损坏

android - Android Studio中的Gradle同步错误