简体   繁体   English

是否可以在图像视图中获取图像的图像路径?

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

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. 不是直接的,一旦在ImageView上设置了ImageView它就变成了Drawable而其他一切都被遗忘了。 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. 您还可以考虑创建ImageView的子类来封装这个额外的函数,以帮助您的代码更容易阅读和维护。

HTH HTH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM