0

In my Android app i have to read a lot of images, for this reason i have implemented image caching. This is the method through which i decode my images(that were stored in the assets/ folder):

private Bitmap getBitmapFromAsset(String strName)
{
    AssetManager assetManager = context.getAssets();
    InputStream istr = null;
    try {

        istr = assetManager.open(strName);

    } catch (IOException e) {
        e.printStackTrace();
    }

    return decodeFileFromAssets(istr);
}

private Bitmap decodeFileFromAssets(InputStream stream ){

        //decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(stream,null,o);

    final int REQUIRED_WIDTH=1280;
    final int REQUIRED_HIGHT=720;

        int scale=1;
    while(o.outWidth/scale/2>=REQUIRED_WIDTH && o.outHeight/scale/2>=REQUIRED_HIGHT)
        scale*=2;

        //decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize=scale;
        return BitmapFactory.decodeStream(stream, null, o2);

}

I have notice that when i read .jpg images its all ok, but when i read .png images i came across to this annoying error:

D/skia﹕ --- SkImageDecoder::Factory returned null

how can i resolve this issue without converting all the .png images into .jpg images??

EDIT

This issue is presenting only when i have to show a .png images from the assets folder and not for all other format. Why?

EDIT 2

I have edited my code in order to explain better the function of my methods...

Francesco Lombardo
  • 335
  • 1
  • 4
  • 15
  • possible duplicate of [Android: SkImageDecoder:: Factory returned null](http://stackoverflow.com/questions/12006785/android-skimagedecoder-factory-returned-null) – petey May 01 '15 at 15:52
  • or http://stackoverflow.com/questions/23559736/android-skimagedecoderfactory-returned-null-error – petey May 01 '15 at 15:54
  • I have read it before to post my question but my problem is different – Francesco Lombardo May 01 '15 at 16:07
  • understood, retracted close vote. – petey May 01 '15 at 16:12
  • how are you calling `decodeFileFromAssets(InputStream stream )` also consider renaming this to `decodeFileFromInputStream` (no biggy tho) – petey May 01 '15 at 16:15
  • @petey i have edited my code... the method is called decodeFileFromAssets becouse it is returned a bitmap that is taken from the assets folder – Francesco Lombardo May 01 '15 at 16:31

0 Answers0