2013-10-15 10 views
22

ライブカメラのフィードを使用してバーコードとqrコードをスキャンするiOSアプリケーションを開発しています。しかし、時々私はエラーを取得します。これらのエラーはアプリケーションをクラッシュさせませんが、それらを修正することをお勧めします。これらはエラーです:CGContextSaveGState無効なコンテキスト

<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; 
} 

答えて

57

UIGraphicsBeginImageContextWithOptions方法はwidth = 0および/またはheight = 0のいずれかでサイズを渡されています。問題をデバッグして解決します。

+0

この解決方法は、この問題の一部のインスタンスを解決する可能性があります。 – Biclops

+3

Omgありがとうございます。このような単純な問題のために、ひどく役に立たないエラーメッセージ。 – devios1

+0

これはあまりにも遊び場で働いた。 UIGraphicsBeginImageContextWithOptions(CGSize(width:500、height:500)、false、1.0) '' 'を吹き飛ばす行の前に' ''を落としました。 :) –

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) 

のように行っているとき、私はそう境界の幅または高さがゼロの場合、このエラーが発生します。誰が実行している場合は

[[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]; 
+1

はい!他のすべてのスレッドをブラウズして解決策を試した後、これが理にかなっています。文脈に描かれている '[UIImage imageNamed:@" placeholder "]'を使って既存の画像のプレースホルダー '[UIImage new]'を変更するまでは間違ったコンテキストが現れました。 – igraczech

1

はSO私はちょうど私がUINavigationBarの外観を変更し、この方法を使用していた

+ (UIImage *)gradientColorImageWithColors:(NSArray *)colorsArray gradientType:(GradientImageType)type andSize:(CGSize)imageSize addingLightEffect:(BOOL)addLightEffect { 

if(imageSize.width==0) { 
    return nil; 
} 

のように私のコードでは、単純な幅非ゼロチェックをしましたこの問題に私の場合、私は誤ってCAShapeLayerのパスにpath.stroke()path.fill()を直接呼んでいました。これらのメソッドは、実際にコンテキストがある場合(つまり、内部がdraw(rect:)の場合)呼び出される必要があります。