0

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

user3051460
  • 1,455
  • 22
  • 58

4 Answers4

2

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

Androider
  • 3,833
  • 2
  • 14
  • 24
1

Use int type to save the drawable id.

Eg.

int drawablePerson = R.drawable.imgPerson;

int drawableId = R.drawable.layoutID;
Prasanna Anbazhagan
  • 1,693
  • 1
  • 20
  • 37
1

Add like this in path..

  String pathPerson="wright your package name:drawable/" + R.drawable.imgPerson;

I think this is work for your problem.

Abhinav singh
  • 1,448
  • 1
  • 14
  • 31
0

first you have to save the data to a file using this method Save Bitmap to File

then you can use Bitmap bitmap = BitmapFactory.decodeFile(String pathName); refer to Android Developer BitmapFactory

Community
  • 1
  • 1
dEv_tO_bE
  • 145
  • 2
  • 12