мне нужно загрузить изображение из ресурсов, чтобы избежать ошибки 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 ();
Я фиксирую исключение FileNotFoundException: radiocd5.png, но этот файл находится у меня каталог ресурсов: S
Что я делаю плохо? Этот файл называется radiocd5.png
и находится в каталоге assets