Alex Rivera | Logout

Show Image View from file path?

Asked 2010-11-15T05:53:29.843
350

I need to show an image by using the file name only, not from the resource id.

ImageView imgView = new ImageView(this);
imgView.setBackgroundResource(R.drawable.img1);

I have the image img1 in the drawable folder. I wish to show that image from the file.

How can I do this?

Edit
Report

1 Answer

5

You can use:

ImageView imgView = new ImageView(this);
InputStream is = getClass().getResourceAsStream("/drawable/" + fileName);
imgView.setImageDrawable(Drawable.createFromStream(is, ""));
answered 2012-05-27T11:24:55.753

Your Answer