Otóż mam pewien problem. Przerobiłem kod ładujący obrazy z resources na assets ( http://developer.android.com/training/displaying-bitmaps/load-bitmap.html ). *.jpg ładuje poprawnie a *.png nie chce załadować.
private Bitmap decodeSampledFromAssets(String path, int reqWidth, int reqHeight) {
InputStream ims = null;
try {
ims = mContext.getAssets().open(path);
final BitmapFactory.Options options = new BitmapFactory.Options();
// 1
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(ims, null, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeStream(ims, null, options);
}
catch (IOException e) {
e.printStackTrace();
}
finally {
if (ims != null) {
try {
ims.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
protected int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) > reqHeight
&& (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}
// przykładowe wywołanie
public void test(){
// ładuje
Bitmap bitmap = decodeSampledFromAssets("test1.jpg", 64, 64);
// nie ładuje
Bitmap bitmap = decodeSampledFromAssets("test2.png", 64, 64);
}