美文网首页
将一个view转化为截图

将一个view转化为截图

作者: 情来情去情随缘 | 来源:发表于2018-03-07 11:49 被阅读0次

开发中遇到问题搜索的结果,来自他人,不做其他用途,未能注明来源,如有侵权联系本人删除。

从图片上抠图

CGImageRef imagRef = CGImageCreateWithImageInRect([image CGImage], r);

UIImage *newImage = [UIImage imageWithCGImage: imagRef]; 

CGImageRelease(imagRef);

image: 原图

r: 需要获取的图片区域

newImage: 目标区域的图片

获取屏幕截图也是很简单的:

//获得屏幕图像 

- (UIImage*)imageFromView: (UIView*) theView      

{       

UIGraphicsBeginImageContext(theView.frame.size);

CGContextRef context = UIGraphicsGetCurrentContext();        

[theView.layer renderInContext:context];

UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();        

UIGraphicsEndImageContext();

return theImage;    

}

相关文章

网友评论

      本文标题:将一个view转化为截图

      本文链接:https://www.haomeiwen.com/subject/rwkjfftx.html