Android: SkImageDecoder:: Factory returned null

前端 未结 5 1055
[愿得一人]
[愿得一人] 2020-11-29 07:58

I\'m using my localhost to fetch images and to view in an ImageView. For some reason I\'m getting Factory returned null error. I\'ve looked through the code many times and I

相关标签:
5条回答
  • 2020-11-29 08:43

    Hi guys I after looking around I got the best solution. as #jia George point out you shold reset the inputstream after first decoding, the issue is that some time reset is not supported but you can wrap inputstream inside a BufferedInputStream and this one is fine.

    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true; 
    BufferedInputStream buffer=new BufferedInputStream(is);
    BitmapFactory.decodeStream(buffer,null,options);
    buffer.reset();
    
        // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth,reqHeight);
    
        // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false; 
    BitmapFactory.decodeStream(buffer,null,options);
    
    0 讨论(0)
  • 2020-11-29 08:44

    As above with Picasso make sure that your url is correct, just copy and paste the link from your development program into your web browser

    I typed:

    http://lorepixel.com/600/400/city

    instead of

    http://lorempixel.com/600/400/city

    0 讨论(0)
  • 2020-11-29 08:45

    I have encountered the same problem. And also I make sure the url is correct to download the image. By debugging the code, I found the variable of position in inputstream was set to 1024 after the first decode. So I add inputstream.reset() before the second decode. That works. Hope can help others.

    0 讨论(0)
  • 2020-11-29 08:47

    This might be a rare case but for those of you using Picasso you'll see this error if you try to load an image from URL but the URL doesn't refer to an image.

    For example:
    http://www.google.ca
    instead of:
    https://www.google.ca/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png

    0 讨论(0)
  • I had a similar problem when reading a stream from an Intent returned from the gallery app. inputstream.reset() throws an IOException, as Shellum mentions above, so I solved it by just closing the stream and reopening it again. Simple, and did the trick.

    0 讨论(0)
提交回复
热议问题