【发布时间】:2010-10-09 21:40:23
【问题描述】:
我需要通过指定文件名而不是使用资源来显示图像。例如 showImage("background.png") 而不是 showImage(R.drawable.background)。
有人知道吗?
非常感谢。
【问题讨论】:
我需要通过指定文件名而不是使用资源来显示图像。例如 showImage("background.png") 而不是 showImage(R.drawable.background)。
有人知道吗?
非常感谢。
【问题讨论】:
阅读此Android Image Tutorial。有一个使用 FileOutputStream 写入图像的示例,我确定也有 FileInputStream。这是another code example,它下载图像并将它们转换为解码后的输入流:
bmImg = BitmapFactory.decodeStream(is);
imView.setImageBitmap(bmImg);
【讨论】:
public static Bitmap decodeFile (String pathName, BitmapFactory.Options opts)
这些选项不是强制性的,但如果您想显示大图像,您也应该提供它们。
【讨论】:
您可以使用下面的方法从资源文件夹中使用它的名称获取图像。
public int getImage(String imageName) {
return this.getResources().getIdentifier(imageName, "drawable", this.getPackageName());
}
【讨论】: