如何从android中的assets文件夹中读取图像并使其在view类中可用

如何从android中的assets文件夹中读取图像并使其在view类中可用,android,image,view,Android,Image,View,我正在加载视图中的图像。 请帮帮我! 例如,我有一个代码: Class myView extends View { // I want to load image in to this view } 在扩展的视图中使用此函数。在此处传递文件名作为参数 private Bitmap getBitmapFromAsset(String strName) { AssetManager assetManager = getAssets(); InputS

我正在加载视图中的图像。 请帮帮我! 例如,我有一个代码:

Class myView extends View

{

// I want to load image in to this view 

}

在扩展的
视图中使用此函数。在此处传递文件名作为参数

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;
    }