How can I fix CGContextRestoreGState: invalid context 0x0
问题 This is the code that I am working with: CGRect imageRect = CGRectMake(0, 0, oldImage.size.width, oldImage.size.height); CGRect newRect = imageRect; UIGraphicsBeginImageContextWithOptions(newRect.size, NO, oldImage.scale); CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextScaleCTM(ctx, 1, -1); CGContextTranslateCTM(ctx, 0, -(newRect.size.height)); CGContextSaveGState(ctx); CGContextClipToMask(ctx, newRect, oldImage.CGImage); CGContextSetFillColorWithColor(ctx, [UIColor colorWithWhite