[英]How to display the image from assets folder in android?
我將我的圖像保存在assets文件夾中並嘗試顯示它們。 我試過很多方面,但仍然無法顯示圖像。 在logcat中它沒有顯示任何錯誤。
關於這個請幫幫我..........
AssetManager mngr = mContext.getResources().getAssets();
is = mngr.open("test3.png");
bitmap = BitmapFactory.decodeStream(is);
Uri uriSavedImage=Uri.fromFile(pictures_directory);
((ImageView) view.findViewById(R.id.imageView1)).setImageBitmap(bitmap);
您可以使用AssetManager
使用其open()
方法獲取InputStream,然后使用BitmapFactory
decodeStream()
方法獲取Bitmap。
private Bitmap getBitmapFromAsset(String strName)
{
AssetManager assetManager = getAssets();
InputStream istr = null;
try {
istr = assetManager.open(strName);
} catch (IOException e) {
e.printStackTrace();
}
Bitmap bitmap = BitmapFactory.decodeStream(istr);
return bitmap;
}
這里有些東西不對,你得到的是什么錯誤? 因為你問題中的錯誤不會出現在下面的代碼中...如果有的話會說“無法打開內容:file:///testing/test3.png”。
這聽起來像你的圖像存儲在錯誤的地方,這就是為什么它說它找不到它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.