I'm trying to save a SwiftUI image (not a UIImage from UIKit) to disk.
I've looked everywhere but could not find any documented information on how to do this. I also cannot see a way to extract the Data from the SwiftUI image.
Can anybody help? Thanks in advance.
Name it img and make sure the attribute type is Binary Data, then click on the img attribute and go to Data Model Inspector. Check the box Allows External Storage. By checking this box, Core Data saves a reference to the data which will make for faster access.
If you have a touchscreen, long tap to bring up the context menu. Select Save Image As. Choose a location and filename. Select Save and you're done!
With SwiftUI, things work a little differently. What you want to do, cannot be done in that fashion. Instead, you need to look at how the image was created and obtain the image data from the same place that your Image()
got it in the first place.
Also if you need the actual binary data to save it to disk, you need a UIImage
(note that I am not saying UIImageView
).
Fortunately, Image can handle UIImage
too, check this other question for that: https://stackoverflow.com/a/57028615/7786555
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With