为了账号安全,请及时绑定邮箱和手机立即绑定

我想要的是区域截图,我要设置origin坐标,然后设置width和height,请问怎么做?

我想要的是区域截图,我要设置origin坐标,然后设置width和height,请问怎么做?

iOS
跃然一笑 2023-04-26 19:15:35
我现在使用如下方法对屏幕截图:UIGraphicsBeginImageContext(self.view.bounds.size);[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];currentCaptureImage = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();
查看完整描述

2 回答

?
汪汪一只猫

TA贡献1898条经验 获得超8个赞

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)];


查看完整回答
反对 回复 2023-04-29
?
PIPIONE

TA贡献1829条经验 获得超9个赞

主要就是下面这句

UIImage *resultImg = [UIImage imageWithCGImage:CGImageCreateWithImageInRect(img.CGImage, rect)];


查看完整回答
反对 回复 2023-04-29
  • 2 回答
  • 0 关注
  • 132 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信