Display image by file name

I need to display an image by specifying a file name, and not using a resource. For example, showImage("background.png")instead of showImage(R.drawable.background).

Does anyone know how?

Many thanks.

+3
source share
3 answers

Read this Android Image Tutorial . Here is an example that uses FileOutputStream to record an image, I am sure FileInputStream too. Here's another example code that downloads images and converts them to an input stream that is decoded:

bmImg = BitmapFactory.decodeStream(is);
imView.setImageBitmap(bmImg);
+1
source

public static Bitmap decodeFile (String pathName, BitmapFactory.Options selects)

, , .

0

You can use the method below to get the image using its name from the resource folder.

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

Source: https://habr.com/ru/post/1703835/


All Articles