Is it possible to get the image path of an image in an image view?

…衆ロ難τιáo~ 提交于 2020-01-05 04:37:06

问题


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);

回答1:


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



来源:https://stackoverflow.com/questions/10883248/is-it-possible-to-get-the-image-path-of-an-image-in-an-image-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!