美文网首页
iOS 17.0 UIGraphicsBeginImageCon

iOS 17.0 UIGraphicsBeginImageCon

作者: 来敲代码 | 来源:发表于2024-02-01 17:08 被阅读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);
    

    相关文章

      网友评论

          本文标题:iOS 17.0 UIGraphicsBeginImageCon

          本文链接:https://www.haomeiwen.com/subject/eedzodtx.html