Подтвердить что ты не робот

CGContextSetFillColorWithColor: недопустимый контекст 0x0

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

Ответ 1

Ваш image.size недействителен, поэтому UIGraphicsBeginImageContextWithOptions не создает графический контекст. Оба image.size.width должны быть положительными, конечными числами.

Возможно <image nil. Когда вы отправляете сообщение size на nil, вы возвращаетесь обратно CGSizeZero.