Android - SkImageDecoder::Factory only when i read image with extension .png
Asked Answered
S

0

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...

Sclerenchyma answered 1/5, 2015 at 15:45 Comment(6)
possible duplicate of Android: SkImageDecoder:: Factory returned nullProliferation
or #23560236Proliferation
I have read it before to post my question but my problem is differentSclerenchyma
understood, retracted close vote.Proliferation
how are you calling decodeFileFromAssets(InputStream stream ) also consider renaming this to decodeFileFromInputStream (no biggy tho)Proliferation
@Proliferation i have edited my code... the method is called decodeFileFromAssets becouse it is returned a bitmap that is taken from the assets folderSclerenchyma

© 2022 - 2024 — McMap. All rights reserved.