我需要通过指定文件名而不是使用资源来显示图像。 E.g showImage("background.png")
代替showImage(R.drawable.background)
。
任何人都知道怎么做?
非常感谢。
答案 0 :(得分:1)
阅读此Android Image Tutorial。有一个使用FileOutputStream来编写图像的例子,我确定也有FileInputStream。这是下载图像并将其转换为已解码的输入流的another code example:
bmImg = BitmapFactory.decodeStream(is);
imView.setImageBitmap(bmImg);
答案 1 :(得分:0)
public static Bitmap decodeFile(String pathName,BitmapFactory.Options opts)
选项不是强制性的,但如果您想要显示大图像,您也应该提供它们。
答案 2 :(得分:0)
您可以使用以下方法从资源文件夹中使用其名称获取图像。
public int getImage(String imageName) {
return this.getResources().getIdentifier(imageName, "drawable", this.getPackageName());
}