我正在开发一个iOS应用程序,它使用实时摄像头源扫描条形码和qr码。但有时我会收到错误..这些错误不会导致应用程序崩溃,但修复它们可能是个好主意。这些是错误:
<Error>: CGContextSaveGState: 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.
<Error>: CGContextSetBlendMode: 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.
<Error>: CGContextSetAlpha: 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.
<Error>: CGContextTranslateCTM: 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.
<Error>: CGContextScaleCTM: 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.
<Error>: CGContextDrawImage: 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.
<Error>: CGContextRestoreGState: 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.
<Error>: CGContextSetInterpolationQuality: 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.
<Error>: CGContextSetAllowsAntialiasing: 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.
<Error>: CGContextTranslateCTM: 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.
<Error>: CGContextScaleCTM: 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.
<Error>: CGContextFlush: 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.
<Error>: CGBitmapContextCreateImage: 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.
<Error>: CGContextSetInterpolationQuality: 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.
<Error>: CGContextSetAllowsAntialiasing: 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.
<Error>: CGContextTranslateCTM: 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.
<Error>: CGContextScaleCTM: 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.
<Error>: CGContextFlush: 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.
<Error>: CGBitmapContextCreateImage: 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.
我相信这段代码对错误信息负责:
- (UIImage *)cropImage:(UIImage *)oldImage sideCrop:(float)crop {
CGSize imageSize = oldImage.size;
UIGraphicsBeginImageContextWithOptions( CGSizeMake( imageSize.width - 2*crop,
imageSize.height ),
NO,
0.);
[oldImage drawAtPoint:CGPointMake( -crop, 0)
blendMode:kCGBlendModeCopy
alpha:1.];
UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return croppedImage;
}
答案 0 :(得分:58)
UIGraphicsBeginImageContextWithOptions
方法通过width = 0
和/或height = 0
传递大小。调试并解决问题。
答案 1 :(得分:6)
如果其他人遇到此问题,我的情况是我错误地直接在CAShapeLayer的路径上调用了path.stroke()
和path.fill()
。只有当您实际拥有上下文(即在draw(rect:)
内)时,才应调用这些方法。
答案 2 :(得分:1)
在执行
时出现此错误UIGraphicsBeginImageContextWithOptions(gradientLayer.bounds.size,
NO,
1.0f);
[gradientLayer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *gradientColorImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
,其中
(lldb) po gradientLayer.bounds
(origin = (x = 0, y = 0), size = (width = 0, height = 0))
(origin = (x = 0, y = 0), size = (width = 0, height = 0))
(lldb) po gradientLayer.bounds.size
(width = 0, height = 0)
(width = 0, height = 0)
所以当边界的宽度或高度为零时。
所以我只是在我的代码中做了一个简单的宽度非零检查,如
+ (UIImage *)gradientColorImageWithColors:(NSArray *)colorsArray gradientType:(GradientImageType)type andSize:(CGSize)imageSize addingLightEffect:(BOOL)addLightEffect {
if(imageSize.width==0) {
return nil;
}
我正在使用此方法更改UINavigationBar的外观:
[[UINavigationBar appearanceWhenContainedIn: [UINavigationController class], nil] setBackgroundImage: [UIImage gradientColorImageWithColors:@[(id)COLORS_NAVIGATION_BAR_1.CGColor, (id)COLORS_NAVIGATION_BAR_2.CGColor]
gradientType:GradientImageTypeHorizontal
andSize:(CGSize){CGRectGetWidth( [UIScreen mainScreen].bounds ), 1.0f}]
forBarMetrics:UIBarMetricsDefault];