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

怎么把一个UIView的指定区域存成图片

怎么把一个UIView的指定区域存成图片

叮当猫咪 2019-03-29 10:58:38
我已经实现了把一个UIView直接生成图片。UIGraphicsBeginImageContext(myView.bounds.size);[myView.layerrenderInContext:UIGraphicsGetCurrentContext()];UIImage*viewImage=UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();但是,我需要截取这个UIView的一部分,比如中间100个像素,怎么实现呢?
查看完整描述

2 回答

?
烙印99

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

[myView.layerrenderInContext:UIGraphicsGetCurrentContext()];这个地方不是已经获取到当前图像的context了么,然后用路径裁剪获取需要的部分应该就可以吧。CGContextBeginPath(context);
CGContextAddRect(context,rect)
CGContextClip(context);不知道可以么,没有试。
                            
查看完整回答
反对 回复 2019-03-29
?
芜湖不芜

TA贡献1796条经验 获得超7个赞

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size,YES,1);
	[self.view.layerrenderInContext:UIGraphicsGetCurrentContext()];
	UIImage*img=UIGraphicsGetImageFromCurrentImageContext();
	
	//UIImageWriteToSavedPhotosAlbum(img,self,nil,nil);
	
	UIGraphicsEndImageContext();self.view就是想要保存的view我没看清楚题目如果是保存指定区域的话,就把上述代码得到的image,通过下面的代码得到所需的指定区域图片并保存。UIImage*resultImg=[UIImageimageWithCGImage:CGImageCreateWithImageInRect(img.CGImage,rect)];
                            
查看完整回答
反对 回复 2019-03-29
  • 2 回答
  • 0 关注
  • 585 浏览
慕课专栏
更多

添加回答

举报

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