1

SwiftUI Image has an initializer to init an Image instance with an UIImage instance via init(uiImage: UIImage). Is there a way to convert the Image instance back to UIImage type?

I found a similar question in How to convert a image to UIImage but it does not answer my question. The motivation is that I need to save the Image to photo album via UIImageWriteToSavedPhotosAlbum(_:_:_:_:)

Obviously we can have another variable to hold the data source, the original UIImage, but I just wonder if that is really necessary.

XY L
  • 25,431
  • 14
  • 84
  • 143
  • Do you actually need a `UIImage`? Would a `UIView` not be sufficient? – Dávid Pásztor Sep 09 '20 at 11:17
  • Hey David, i updated my question. I need UIImage to save it to photo album – XY L Sep 09 '20 at 11:20
  • 1
    How are you creating the SwiftUI `Image`? And what code are you trying to use to save to photo album? Maybe there is an alternative that takes `Data` instead of a `UIImage`. – Dávid Pásztor Sep 09 '20 at 11:21
  • 1
    Yes, you should only have an `Image` for the purposes of displaying something in SwiftUI. The thing that you save to the photo album will need to come from your original source. – Paulw11 Sep 09 '20 at 11:22
  • thanks @Paulw11 and @David. it sounds like `Image` is a dead-end once it is initiated so no data can be extracted from it any more – XY L Sep 09 '20 at 11:24

0 Answers0