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

时间:2012-06-04 14:44:38

标签: android sql image path

我在图片视图中设置了图片。现在我想保存这个状态,需要知道该图像的图像路径。有没有办法做到这一点?

更新:

// 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 个答案:

答案 0 :(得分:3)

不是直接的,一旦在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

相关问题