I want to show an image in imageview so I made a folder - drawable
in res
and put my image there. Something like apple.png
. Then I use this code:
ImageView iv= (ImageView)findViewById(R.id.img_selected_image); String path = getApplication().getFilesDir().getAbsolutePath(); InputStream is = new FileInputStream(path + "/apple.png"); Drawable icon = new BitmapDrawable(is); Log.i("Fnord", "width="+icon.getIntrinsicWidth()+ " height="+icon.getIntrinsicHeight()); iv.setImageDrawable(icon);
But when i run it, it said there isn't any image by apple.png
name in data/data/package-name/files
. I think i put my image in inappropriate place. Where should i put my image ?
xml (or any activity you need to add image) and select the Design view. There you can see your Palette tool box on left side. You need to drag and drop ImageView. Select the image you want press Ok you can see the image on the Design view.
To import image resources into your project, do the following: Drag and drop your images directly onto the Resource Manager window in Android Studio. Alternatively, you can click the plus icon (+), choose Import Drawables, as shown in figure 3, and then select the files and folders that you want to import.
In Android, ImageView class is used to display an image file in application. Image file is easy to use but hard to master in Android, because of the various screen sizes in Android devices.
you can directly give the Image name in your setimage as iv.setImageResource(R.drawable.apple);
that should be it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With