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

自古美人都是妖i 提交于 2019-12-12 06:13:46

问题


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

来源:https://stackoverflow.com/questions/29990186/android-skimagedecoderfactory-only-when-i-read-image-with-extension-png

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!