0

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.

Pjaks
  • 251
  • 1
  • 11
  • How did you want to show it? As a UIImage? Then wrap the CGImage in a UIImage. Unclear what the issue is here. – matt Jul 11 '22 at 13:00
  • I just need to show it. So I tried to wrap the CGImage in a UIImage. Now I get the error-message: "Referencing static method 'buildBlock' on 'Optional' requires that 'UIImage' conform to 'View'" and "Static method 'buildBlock' requires that 'UIImage' conform to 'View'" – Pjaks Jul 11 '22 at 13:07

1 Answers1

1

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

if let cgImage = EFQRCode.generate(for: "test") {
    Image(uiImage: UIImage(cgImage: cgImage))
}
Asperi
  • 228,894
  • 20
  • 464
  • 690