简体   繁体   中英

How do you get URL from UIImage in Swift or Objective C?

I have a UIImage object like this (in Swift):

image : UIImage = UIImage(contentsOfFile: imagePath)
self.imageView.image = image
// Want to do:
// seeImagePath : String = imagePath

How do I get back the imagePath of this image?

The image (UIImage) has no "path". It is an image, not a file. It is nothing but a bitmap of colors being held in memory.

You had the path before, when you had a variable called imagePath ; if you want to retain that info, retaining it is up to you. It has nothing whatever to do with the UIImage.

UIImage holds the data retrieved from the contents of that file. Once it has loaded the file, it won't know the path of the file. You will need to cache your imagePath variable and refer to that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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