我想不使用id在imageview中显示图像。
我会把所有的图片放在raw文件夹中并打开
try {
String ss = "res/raw/images/inrax/3150-MCM.jpg";
in = new FileInputStream(ss);
buf = new BufferedInputStream(in);
Bitmap bMap = BitmapFactory.decodeStream(buf);
image.setImageBitmap(bMap);
if (in != null) {
in.close();
}
if (buf != null) {
buf.close();
}
} catch (Exception e) {
Log.e("Error reading file", e.toString());
}但是这不起作用,我想使用其路径而不是名称来访问图像
发布于 2010-09-12 04:44:45
您也许能够对原始文件使用Resources.getIdentifier(name, type, package)。这将为您获取id,然后您可以继续使用setImageResource(id)或其他任何东西。
int id = getResources().getIdentifier("3150-MCM", "raw", getPackageName());
if (id != 0) //if it's zero then its not valid
image.setImageResource(id);是你想要的吗?它可能不喜欢多个文件夹,但值得一试。
https://stackoverflow.com/questions/3691295
复制相似问题