【问题标题】:CGImageCreate: invalid image alphaInfoCGImageCreate:无效的图像 alphaInfo
【发布时间】:2021-04-04 20:31:18
【问题描述】:

我遇到了一个奇怪的错误,我无法确定是代码的哪一部分导致了它。

在运行使用相机图像检测条形码的 iOS 应用时,我收到以下错误:

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

我无法弄清楚这是从哪里触发的。有人可以帮忙吗?

到目前为止我已经尝试过:

  1. 使用NSLog 添加符号调试器,假设这是一个日志输出,但调试器没有捕获它。

  2. 由于错误提到图像没有正确的 alphaInfo,我尝试将 alpha 添加到 UIImage 被修改的所有地方(它正在被修改以进行裁剪和旋转)

还有什么我应该尝试的吗?

P.S.:该应用是使用 Cordova 的混合应用,之前使用 XCode < 12 编译并在 iOS < 14 上运行时不会出现此错误。

P.P.S.:我对 iOS/objective-c 很陌生。如果需要,我可以提供更多日志。

【问题讨论】:

  • 没有检测到任何条码。应用程序的其余部分按预期工作。

标签: ios objective-c xcode alpha cgimage


【解决方案1】:

如果创建CGImage 对象,请尝试将bitmapInfo 赋予CGImage 初始化器。

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
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-11
    • 1970-01-01
    • 1970-01-01
    • 2019-03-27
    相关资源
    最近更新 更多