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、把圈內(nèi)的部分從截屏的圖片內(nèi)剪切出來
- (UIImage *)imageFromImage:(UIImage *)image inRect:(CGRect)rect {
CGImageRef sourceImageRef = [image CGImage];
CGImageRef newImageRef = CGImageCreateWithImageInRect(sourceImageRef, rect);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
return newImage;
}