gpt4 book ai didi

ios - 以编程方式创建 UIImage - 代码错误

转载 作者:行者123 更新时间:2023-11-28 05:33:13 25 4
gpt4 key购买 nike

我编写了 UIImage 的这个简单扩展,以从预定义的颜色和大小开始绘制图像。

这是代码:

extension UIImage {

class func image(color:UIColor, size:CGSize)->UIImage {

UIGraphicsBeginImageContextWithOptions(size, true, 2.0);

let context = UIGraphicsGetCurrentContext()
let rect = CGRectMake(0, 0, size.width, size.height)

color.set()

CGContextFillRect(context, rect)
var image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

return image
}
}

如果我在 Controller 的 ViewDidLoad 方法中启动此代码,我会收到此错误

Oct 31 16:48:02 iPhone Budjet_v2[3387] <Error>: CGContextSetFillColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
Oct 31 16:48:02 iPhone Budjet_v2[3387] <Error>: CGContextSetStrokeColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
Oct 31 16:48:02 iPhone Budjet_v2[3387] <Error>: CGContextFillRects: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
fatal error: unexpectedly found nil while unwrapping an Optional value

我不明白我的代码有什么问题。

最佳答案

这似乎是 iOS 7 中引入的错误。答案 here 中列出了导致此错误的方法的完整列表。 .

这个问题的建议操作过程是向 CGPostError 添加一个符号断点,以便在发生此错误时分析堆栈,以确定触发此错误的原因。

此错误可能由多种情况触发,如果不进行进一步研究,则无法确定是哪些情况触发了错误。

祝你好运!

关于ios - 以编程方式创建 UIImage - 代码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26678703/

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