Android 按文件名显示图像

Android 按文件名显示图像,android,imageview,Android,Imageview,我需要通过指定文件名而不是使用资源来显示图像。例如showImage(“background.png”)而不是showImage(R.drawable.background) 有人知道怎么做吗 非常感谢。读一下这个。有一个使用FileOutputStream编写图像的示例,我确信也有FileInputStream。以下是下载图像并将其转换为解码的输入流的示例: bmImg = BitmapFactory.decodeStream(is); imView.setImageBitmap(bmImg)

我需要通过指定文件名而不是使用资源来显示图像。例如
showImage(“background.png”)
而不是
showImage(R.drawable.background)

有人知道怎么做吗

非常感谢。

读一下这个。有一个使用FileOutputStream编写图像的示例,我确信也有FileInputStream。以下是下载图像并将其转换为解码的输入流的示例:

bmImg = BitmapFactory.decodeStream(is);
imView.setImageBitmap(bmImg);
公共静态位图解码文件(字符串路径名,BitmapFactory.Options选项)


这些选项不是必需的,但如果您想显示大图像,您也应该提供它们。

您可以使用下面的方法从资源文件夹中使用图像名称获取图像

public int getImage(String imageName) {
    return this.getResources().getIdentifier(imageName, "drawable", this.getPackageName());
}