Put resources in drawable
ImageView imgView=new ImageView(this);
imgView.setBackgroundResource(R.drawable.img1);
I set it up in imageView like this. Instead of registering resources in the drawable folder, I want to set the imageView by giving the path of the file. How shall I do it?
android imageview android-imageview android-file
If you want to receive the path of the image from SD-Card and register it in ImageView, Using Bitmap
File imgFile = new File("/sdcard/Images/test_image.jpg");
if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);
myImage.setImageBitmap(myBitmap);
}
You can do it like this.
Of course, in the Android manifest file,
<uses-permission android:name="android.permission.You must register WRITE_EXTERNAL_STORAGE" />
© 2024 OneMinuteCode. All rights reserved.