我只是使用CGImageSourceCreateThumbnailAtIndex来缩小UIImage大小。我收到了坠机信息:
"IIONumber -- 'num‘不是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)
}
}
}
}发布于 2019-04-06 14:48:06
传递给CGImageSourceCreateThumbnailAtIndex方法的字典选项包含kCGImageSourceThumbnailMaxPixelSize。应该是CFNumber。
苹果在kCGImageSourceThumbnailMaxPixelSize上的文档
缩略图的最大宽度和高度,以像素为单位。如果未指定此键,则缩略图的宽度和高度不受限制,缩略图可能与图像本身一样大。如果存在,则此键必须是CFNumber值。
请确保它是CFNumber。我相信这就是坠机的原因。请查找苹果的参考资料:https://developer.apple.com/documentation/imageio/kcgimagesourcethumbnailmaxpixelsize?language=objc
试试这样的选择。
let options = [
kCGImageSourceCreateThumbnailWithTransform: true,
kCGImageSourceCreateThumbnailFromImageAlways: true,
kCGImageSourceThumbnailMaxPixelSize: 250 /* some size */] as CFDictionaryhttps://stackoverflow.com/questions/55548162
复制相似问题