Мне нужно загрузить изображение из активов, чтобы избежать ошибки в файле froyo 2.2.2, изменяя размеры изображений POT в некоторых частных случаях. Способ избежать загрузки файлов изображений из каталога ресурсов.
Я пытаюсь сделать это:
String imagePath = "radiocd5.png";
AssetManager mngr = context.getAssets();
// Create an input stream to read from the asset folder
InputStream is=null;
try {
is = mngr.open(imagePath);
} catch (IOException e1) { e1.printStackTrace();}
//Get the texture from the Android resource directory
//InputStream is = context.getResources().openRawResource(R.drawable.radiocd5);
Bitmap bitmap = null;
try {
//BitmapFactory is an Android graphics utility for images
bitmap = BitmapFactory.decodeStream(is);
} finally {
//Always clear and close
try {
is.close();
is = null;
} catch (IOException e) {
}
}
Но я получаю NullPointerException в строке is.close();
i захватывает FileNotFoundException: radiocd5.png, но этот файл находится в моем каталоге ресурсов: S
Что я делаю плохо? Файл называется radiocd5.png
, и он находится в каталоге assets