簡體   English   中英

是否可以在圖像視圖中獲取圖像的圖像路徑?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM