Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a image to UIImage

since the documentation on swiftUI isn't great yet I wanted to ask how I can convert an "image" to an "UIImage" or how to convert an "image" to pngData/jpgData

let image = Image(systemName: "circle.fill")
let UIImage = image as UIImage
like image 631
nOk Avatar asked Jul 14 '19 14:07

nOk


People also ask

What is a UIImage?

An object that manages image data in your app.

How do I add an image to UIImageView?

The first step is to drag the UIImageView onto your view. Then open the UIImageView properties pane and select the image asset (assuming you have some images in your project). You can also configure how the underlying image is scaled to fit inside the UIImageView.

How do I display an image in SwiftUI?

You can display an image in a SwiftUI view by using the Image view. First you need to add the image to a new image set in your Assets. xcassets file in the Xcode project navigator.


1 Answers

Such thing is not possible with SwiftUI, and I bet it will never be. It goes againts the whole framework concept. However, you can do:

let uiImage = UIImage(systemName: "circle.fill")
let image = Image(uiImage: uiImage)
like image 163
kontiki Avatar answered Sep 18 '22 14:09

kontiki