首页 > 解决方案 > 未知进程名称 - vImageConvert_AnyToAny - 在 beginBackgroundTask 上失败

问题描述

嘿,所以我正在后台线程上调整图像的大小,该线程在应用程序进入后台后继续执行beginBackgroundTask以及其他一些代码,如下所示:

func resizeImage(image: UIImage, newWidth: CGFloat) -> UIImage {
  let scale = newWidth / image.size.width
  let newHeight = image.size.height * scale
  UIGraphicsBeginImageContext(CGSize(width: newWidth, height: newHeight))
        
  image.draw(in: CGRect(x: 0, y: 0, width: newWidth, height: newHeight))
  let newImage = UIGraphicsGetImageFromCurrentImageContext()
  UIGraphicsEndImageContext()
  return newImage!
} 

当我触发调整大小并返回主屏幕时,我会收到一堆以下错误。但是,如果我让它在前台运行,它会完美运行。

[未知进程名称] vImageConvert_AnyToAny - 失败宽度 = 0 高度 = 1 dst 组件 = 8 位整数 dstLayout = ByteOrder32Little dstBytesPerRow = 0 src 组件 = 8 位整数 srcLayout = ByteOrderDefault srcBytesPerRow = 0

当我设置断点时,我不能肯定地说我的调整大小逻辑正在吐出这些错误,但它必须是因为它可能是由orvImageConvert_AnyToAny调用的低级图像 api 。UIGraphicsGetImageFromCurrentImageContextdraw

如何摆脱这些错误?

标签: swiftuigraphicscontextuibackgroundtask

解决方案


推荐阅读