繁体   English   中英

如何在android中显示assets文件夹中的图像?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM