我需要加载从资产的图像,以避免升级Froyo 2.2.2错误调整POT图像在某些特殊情况下。的方式,以避免它是从资产目录加载的图像文件。
i need to load a image from assets to avoid a froyo 2.2.2 bug resizing POT images in some particular cases. The way to avoid it is loading the image files from assets dir.
我想用这样的:
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,但该文件是对我的资产目录:•
i capture a FileNotFoundException: radiocd5.png, but that file is on my assets directory :S
我在做什么不好?该文件称为 radiocd5.png
,它是在资产
目录
What am i doing bad? The file is called radiocd5.png
and it is on the assets
directory
您可以按照我的教程从资产中显示的数据:的 HTTPS://xjaphx.word$p$pss.com/2011/10/02/store-and-use-files-在-资产/ 与装载图片和文字的样品显示。
You can follow my tutorials on displaying data from Assets: https://m.xsw88.com/allimgs/daicuo/20230907/5009.png.jpg"); // load image as Drawable Drawable d = Drawable.createFromStream(ims, null); // set image to ImageView mImage.setImageDrawable(d); } catch(IOException ex) { return; }
上一篇:如何在 C++ 中创建一个位于堆而不是堆栈的数组?堆栈、数组、创建一个、而不是
下一篇:需要understad AudioRecord和AudioTrack如何为原料PCM采集和回放工作工作、为原料、AudioRecord、understad