I was successful to load image to linear layout and image from local path as below code
ImageView imagePerson=(ImageView) findViewById(R.id.imgPerson);
LinearLayout layoutID=(LinearLayout)findViewById(R.id.layoutID);
imagePerson.setImageResource(R.drawable.image1);
layoutID.setBackgroundResource(R.drawable.layout1);
However, I need to save the path of these image in to file. Thus, I cannot use above code to load image to imageview and linearlayout. Instead of this, I want to find the way to load image from path. Could you help me to solve it in android. This is my code to get path
String pathPerson="drawable://" + R.drawable.imgPerson;
String pathID="drawable://" + R.drawable.layoutID;
Thanks in advance
Some ways are:
String imageUri = "drawable://" + R.drawable.image;
Other ways :
Uri path = Uri.parse("android.resource://com.segf4ult.test/" + R.drawable.icon);
Uri otherPath = Uri.parse("android.resource://com.segf4ult.test/drawable/icon");
String path = path.toString();
String path = otherPath .toString();
You can Create a Drawable from a String path like this:
String pathGet = "/path/to/file/myFile.jpg";
Drawable d = Drawable.createFromPath(pathGet);
Thanks
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments