ios 如何区域截图

我现在使用如下方法对屏幕截图:
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
currentCaptureImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
但我想要的是区域截图,也就是说,我要设置origin坐标,然后设置width和height,请问怎么做?

阅读 17.9k
2 个回答

CGRect rect =self.view.frame;
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

float originX ;
float originy ;
float width ;
float height ;
//你需要的区域起点,宽,高;

CGRect rect1 = CGRectMake(originX , originY , width , height);
UIImage * imgeee = [UIImage imageWithCGImage:CGImageCreateWithImageInRect([img CGImage], rect1)];

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题