Android: SkImageDecoder:: Factory returned null

前端 未结 5 1073
[愿得一人]
[愿得一人] 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);
    

提交回复
热议问题