Android 资产中的BitmapFactory.decode文件不';t工作(FileNotFindException)
我不知道为什么Android 资产中的BitmapFactory.decode文件不';t工作(FileNotFindException),android,bitmapfactory,android-assets,Android,Bitmapfactory,Android Assets,我不知道为什么decodeFile在参数指向资产文件夹中的文件时不起作用 // Load images from the file path String[] dir = null; try { dir = GenericMainContext.sharedContext.getAssets().list("drawable"); // dir Log => [ic.png, ic_info_dark.png, ic_launcher
decodeFile
在参数指向资产文件夹中的文件时不起作用
// Load images from the file path
String[] dir = null;
try {
dir = GenericMainContext.sharedContext.getAssets().list("drawable");
// dir Log => [ic.png, ic_info_dark.png, ic_launcher_default.png]
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (String uri : dir){
// do your stuff here
if (uri!=null) {
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeFile("file:///android_asset/drawable/"+uri); } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
有什么解释吗?
file:///android_asset/
由WebView用于加载资产。要以编程方式加载资产,请使用getAssets()
方法,该方法在上下文
对象(如活动
)上返回一个AssetMAnager
。open(filename)
将向您的资产文件返回InputStream
。下面将从活动
中的资产文件文件名
创建一个位图
BitmapFactory.decodeStream(getAssets().open(fileName))
有什么解释吗?是,
fileName
在资产中不存在……我检查了fileName
exist;)不,它不。。。我有更多的代表。。。我赢了。。。或者你会证明它的存在…看这里不要用file:///android_asset/
,使用getAssets().open(“drawable/”+uri)
@abdellahn未更改相同结果位图null
不使用file:///android_asset/
,使用getAssets().open(“drawable/”+uri)
@Abdellah