Sterex
Sterex

Reputation: 1028

CGImageCreate: invalid image alphaInfo

I am getting a weird error that I am not able to pin point which part of the code is causing it.

When running an iOS app that uses the camera image to detect barcodes, I get the following error:

2020-12-27 23:58:53.674730+0100 MYAPP[11942:4109474] [Unknown process name] CGImageCreate: invalid image alphaInfo: kCGImageAlphaNone. It should be kCGImageAlphaNoneSkipLast

I am not able to figure out where this is fired from. Can someone help, please?

So far I have tried:

  1. Adding a symbolic debugger with NSLog assuming this was a log output, but the debugger does not catch it.

  2. Since the error mentions that the image does not have a proper alphaInfo, I tried adding an alpha to all the places where UIImage is getting modified (it is getting modified for cropping and rotation)

Anything else I should try?

P.S.: The app is a hybrid app using Cordova and this error did not occur previously when compiled with XCode < 12 and run on iOS < 14.

P.P.S.: I am very new to iOS/objective-c. I can provide more logs if required.

Upvotes: 2

Views: 2411

Answers (1)

ceng2043
ceng2043

Reputation: 31

If you create CGImage object, try to give bitmapInfo to CGImage initializer.

let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.noneSkipLast.rawValue)
let cgImage = CGImage(
    width: width,
    height: height,
    bitsPerComponent: bitsPerComponent,
    bitsPerPixel: bitsPerPixel,
    bytesPerRow: bytesPerRow,
    space: colorSpace,
    bitmapInfo: bitmapInfo,
    provider: provider,
    decode: nil,
    shouldInterpolate: true,
    intent: CGColorRenderingIntent.defaultIntent
)

Upvotes: 3

Related Questions