1、待用户对图片移动和缩放后截屏操作得到用户想要的效果。
-(UIImage *)screenCapture{
UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO , [[UIScreen mainScreen] scale]);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
2、计算用户圈住的部分在整个截屏的位置
-(CGRect)clipRect:(UIView *)view{
CGRect rect = view.frame;
rect.origin.x*=[UIScreen mainScreen].scale;
rect.origin.y*=[UIScreen mainScreen].scale;
rect.size.width*=[UIScreen mainScreen].scale;
rect.size.height*=[UIScreen mainScreen].scale;
return rect;
}
3、把圈内的部分从截屏的图片内剪切出来
- (UIImage *)imageFromImage:(UIImage *)image inRect:(CGRect)rect {
CGImageRef sourceImageRef = [image CGImage];
CGImageRef newImageRef = CGImageCreateWithImageInRect(sourceImageRef, rect);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
return newImage;
}