19

CGContextSetFillColorWithColor: 無効なコンテキスト 0x0。これは重大なエラーです。このアプリケーション、またはアプリケーションが使用するライブラリは、無効なコンテキストを使用しているため、システムの安定性と信頼性が全体的に低下しています。この通知は厚意によるものです。この問題を修正してください。今後のアップデートで致命的なエラーになります。

このメソッドの [color setFill] 行からエラーが発生しています。どうすれば解決できるかについてのアイデアはありますか?

+ (UIImage *)fillImage:(UIImage*)image withColor:(UIColor *)color
{

    // begin a new image context, to draw our colored image onto
    UIGraphicsBeginImageContextWithOptions(image.size, NO, [[UIScreen mainScreen] scale]);

    // get a reference to that context we created
    CGContextRef context = UIGraphicsGetCurrentContext();

    // set the fill color
    [color setFill];

    // translate/flip the graphics context (for transforming from CG* coords to UI* coords
    CGContextTranslateCTM(context, 0, image.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);

    // set the blend mode to overlay, and the original image
    CGContextSetBlendMode(context, kCGBlendModeOverlay);
    CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
    //if(overlay) CGContextDrawImage(context, rect, img.CGImage);

    // set a mask that matches the shape of the image, then draw (overlay) a colored rectangle
    CGContextClipToMask(context, rect, image.CGImage);
    CGContextAddRect(context, rect);
    CGContextDrawPath(context,kCGPathFill);

    // generate a new UIImage from the graphics context we drew onto
    UIImage *coloredImg = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    //return the color-burned image
    return coloredImg;
}
4

1 に答える 1

20

あなたimage.sizeは有効でUIGraphicsBeginImageContextWithOptionsはないため、グラフィックスコンテキストを作成していません。と は両方ともimage.size.widthimage.size.height正の有限数でなければなりません。

おそらくimageそれ自体ですnilsizeメッセージをに送信するとnil、 が返されCGSizeZeroます。

于 2013-11-12T22:31:08.637 に答える