打开一个文件,从资产的文件夹中的android [英] Opening a File from assets folder in android
本文介绍了打开一个文件,从资产的文件夹中的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个.gif文件内的资产文件夹这样的资产/文件/ android.gif。当我尝试打开该文件时,它抛出一个异常,在第二行
I have a .gif file inside the assets folder like this assets/Files/android.gif. when I try to open the file it throws an exception at the second line
AssetManager mngr=getAssets();
InputStream is2=mngr.open("Files/android.gif");
那么,这是我想尽管同样code的作品,如果我尝试打开一个文本文件打开一个图像文件? 有什么可以是这里的问题。
so Is it that I'm trying to open an image file despite that the same code works if I try to open a text file ? what can be the problem here.
推荐答案
这些线路都可以正常使用 -
These Lines are working perfectly--
InputStream bitmap=null;
try {
bitmap=getAssets().open("icon.png");
Bitmap bit=BitmapFactory.decodeStream(bitmap);
img.setImageBitmap(bit);
} catch (IOException e) {
e.printStackTrace();
} finally {
if(bitmap!=null)
bitmap.close();
}
如果你的形象是非常大的,那么你应该将其解码成位图前缩放图像。 看看怎样显示大图有效
If your image is very big then you should scale your image before decoding it into Bitmap. See How to display large image efficiently
这篇关于打开一个文件,从资产的文件夹中的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文