gpt4 book ai didi

ios - 当我在 Swift 中使用 CGImageSourceCreateThumbnailAtIndex 时应用程序崩溃

转载 作者:行者123 更新时间:2023-11-29 05:52:21 27 4
gpt4 key购买 nike

我只是使用CGImageSourceCreateThumbnailAtIndex来缩小UIImage尺寸。我收到崩溃消息:

"IIONumber -- 'num' is not a CFNumberRef" .

我没找到这是什么?谢谢

func scaleDownImage()->void{   

var nextImage = UIImage()
if let img = nextDicData["img"] as? UIImage{
let data = UIImagePNGRepresentation(img)
if let cgimageSource = CGImageSourceCreateWithData(data! as CFData, nil){
let option : [NSString : Any] = [kCGImageSourceThumbnailMaxPixelSize : self.outputSize, kCGImageSourceCreateThumbnailFromImageAlways : true]
// That's crash at bellow line
if let scaleImage = CGImageSourceCreateThumbnailAtIndex(cgimageSource, 0, option as CFDictionary){
nextImage = UIImage(cgImage: scaleImage)
}
}
}
}

最佳答案

传递给 CGImageSourceCreateThumbnailAtIndex 方法的字典选项包含 kCGImageSourceThumbnailMaxPixelSize。它应该是CFNumber。

Apple 关于 kCGImageSourceThumbnailMaxPixelSize 的文档

The maximum width and height in pixels of a thumbnail. If this key is not specified, the width and height of a thumbnail is not limited and thumbnails may be as big as the image itself. If present, this key must be a CFNumber value.

请确保它是CFNumber。我相信这就是坠机的原因。请在此处查找 Apple 的引用信息:https://developer.apple.com/documentation/imageio/kcgimagesourcethumbnailmaxpixelsize?language=objc

尝试这样的选项。

let options = [
kCGImageSourceCreateThumbnailWithTransform: true,
kCGImageSourceCreateThumbnailFromImageAlways: true,
kCGImageSourceThumbnailMaxPixelSize: 250 /* some size */] as CFDictionary

关于ios - 当我在 Swift 中使用 CGImageSourceCreateThumbnailAtIndex 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55548162/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com