iOS 17.0 UIGraphicsBeginImageCon

2024-02-01  本文已影响0人  来敲代码

YBImageBrowser 闪退


UIImage *YBIBSnapshotView(UIView *view) {
//    UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, [UIScreen mainScreen].scale);
//    [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];
//    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
//    UIGraphicsEndImageContext();
    
    CGSize size = view.bounds.size;
    UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
    format.scale = [UIScreen mainScreen].scale;
    UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:size format:format];
    UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
    }];
    return image;
}

YYTextAsyncLayer 闪退

//        UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, self.contentsScale);
//        CGContextRef context = UIGraphicsGetCurrentContext();
//        if (self.opaque) {
//            CGSize size = self.bounds.size;
//            size.width *= self.contentsScale;
//            size.height *= self.contentsScale;
//            CGContextSaveGState(context); {
//                if (!self.backgroundColor || CGColorGetAlpha(self.backgroundColor) < 1) {
//                    CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
//                    CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
//                    CGContextFillPath(context);
//                }
//                if (self.backgroundColor) {
//                    CGContextSetFillColorWithColor(context, self.backgroundColor);
//                    CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
//                    CGContextFillPath(context);
//                }
//            } CGContextRestoreGState(context);
//        }
//        task.display(context, self.bounds.size, ^{return NO;});
//        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
//        UIGraphicsEndImageContext();
//        self.contents = (__bridge id)(image.CGImage);
        UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
              format.opaque = self.opaque;
              format.scale = self.contentsScale;

              UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:self.bounds.size format:format];
              UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
                  CGContextRef context = rendererContext.CGContext;
                  if (self.opaque) {
                      CGSize size = self.bounds.size;
                      size.width *= self.contentsScale;
                      size.height *= self.contentsScale;
                      CGContextSaveGState(context); {
                          if (!self.backgroundColor || CGColorGetAlpha(self.backgroundColor) < 1) {
                              CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
                              CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
                              CGContextFillPath(context);
                          }
                          if (self.backgroundColor) {
                              CGContextSetFillColorWithColor(context, self.backgroundColor);
                              CGContextAddRect(context, CGRectMake(0, 0, size.width, size.height));
                              CGContextFillPath(context);
                          }
                      } CGContextRestoreGState(context);
                  }
                  task.display(context, self.bounds.size, ^{return NO;});
              }];

              self.contents = (__bridge id)(image.CGImage);
上一篇下一篇

猜你喜欢

热点阅读