I have set an image in an image view. Now I want to save this state and need to know the image path of that image. Is there a way to do that?
UPDATE:
// Decode, scale and set the image.
Bitmap myBitmap = BitmapFactory.decodeFile(selectedImagePath);
Bitmap scaledBitmap = Bitmap.createScaledBitmap(myBitmap, NEW_WIDTH, NEW_HEIGHT, true);
myBitmap.recycle();
myBitmap = null;
mImageView.setImageBitmap(scaledBitmap);
Not directly, once an image is set on an ImageView
it is turned into a Drawable
and all else is forgotten. However, you could use tags for this purpose. Any view can have a tag associated with it that represents some metadata about that view. You could do something like:
ImageView iv; //Declared elsewhere
Uri imagePath = Uri.parse("...");
//Set the image itself
iv.setImageURI(imagePath);
//Add the path value as a tag
iv.setTag(imagePath);
//Sometime in the future, retrieve it
Uri path = (Uri)iv.getTag();
You might also consider creating a subclass of ImageView
to encapsulate this extra function to help make your code a little easier to read and maintain.
HTH
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.