iOS 截屏代码

-(UIImage*)getScreenPhoto{

    CGFloat scale = [UIScreen mainScreen].scale;

    NSMutableArray *images = [NSMutableArray array];

    

    CGSize contentSize = self.view.size;

    

    CGSize imageSize = CGSizeMake(contentSize.width * scale, contentSize.height * scale);

    

    UIGraphicsBeginImageContextWithOptions(self.view.size, NO, 0.0);

    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    [images addObject:image];

    

    UIGraphicsBeginImageContext(imageSize);

    

    [images enumerateObjectsUsingBlock:^(UIImage *image, NSUInteger idx, BOOL *stop) {

        [image drawInRect:CGRectMake(0, scale * EJScreenH * idx, EJScreenW * scale, EJScreenH * scale)];

    }];

    UIImage *fullImage = UIGraphicsGetImageFromCurrentImageContext();

    

    UIGraphicsEndImageContext();

  return fullImage;

    

}

posted @ 2017-10-09 16:47  jsonLing  阅读(603)  评论(1编辑  收藏  举报