是否可以在图像视图中获取图像的图像路径? [英] Is it possible to get the image path of an image in an image view?

查看:97
本文介绍了是否可以在图像视图中获取图像的图像路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在图像视图中设置了图像.现在,我要保存此状态,并且需要知道该图像的图像路径.有办法吗?

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?

更新:

// 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上后,便将其转换为Drawable,而所有其他内容都将被遗忘.但是,您可以将标签用于此目的.任何视图都可以具有与之关联的标签,该标签表示有关该视图的一些元数据.您可以执行以下操作:

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

您还可以考虑创建ImageView的子类来封装此额外功能,以帮助使您的代码更易于阅读和维护.

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

这篇关于是否可以在图像视图中获取图像的图像路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆