[英]Is it possible to get the image path of an image in an image view?
我在图像视图中设置了图像。 现在我想保存这个状态,需要知道该图像的图像路径。 有没有办法做到这一点?
更新:
// 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);
不是直接的,一旦在ImageView
上设置了ImageView
它就变成了Drawable
而其他一切都被遗忘了。 但是,您可以使用标记来实现此目的。 任何视图都可以有一个与之关联的标记,表示该视图的一些元数据。 你可以这样做:
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();
您还可以考虑创建ImageView
的子类来封装这个额外的函数,以帮助您的代码更容易阅读和维护。
HTH
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.