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...
decodeFileFromAssets(InputStream stream )
also consider renaming this todecodeFileFromInputStream
(no biggy tho) – Proliferation