Home > Back-end >  Convert CGImage? to an Image I can show in my view (swiftUI)
Convert CGImage? to an Image I can show in my view (swiftUI)

Time:07-12

I am working with EFQRCode library and am trying to generate a QR-code on my apple watch. The result of EFQRCode.generate(for: "test") is a CGImage. If I print the line above I get something like this:

Optional(<CGImage 0x16db3160> (DP) <<CGColorSpace 0x16d5c750> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)> width = 600, height = 600, bpc = 8, bpp = 32, row bytes = 2400 kCGImageAlphaPremultipliedFirst | kCGImageByteOrder32Little | kCGImagePixelFormatPacked is mask? No, has masking color? No, has soft mask? No, has matte? No, should interpolate? Yes)

Is there a way of turning this into an image I can show on the watch? Or are there any other ways of creating a QR-code on the apple-watch. Thanks in advance.

CodePudding user response:

It is possible to create Image via UIImage created with CGImage, like

if let cgImage = EFQRCode.generate(for: "test") {
    Image(uiImage: UIImage(cgImage: cgImage))
}
  • Related