作者whitefur (白毛)
看板MacDev
标题[问题] UIView特定范围截图
时间Fri Oct 18 12:47:02 2013
想在UIView上特定区城的做截图
目前找到最接近的方法只能截出左上角
假设要截取左上角长宽200的区城
UIGraphicsBeginImageContextWithOptions(CGSizeMake(200, 200), self.view.opaque, self.view.contentScaleFactor);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
请问该如何截出左上角以外的特定区城呢?
感谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 1.160.26.73
1F:→ nobody1:CGContextMoveToPoint 试一下 换掉cgpoint 10/18 13:02
自问自答
把上面的第一行改成UIView的size
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size,
self.view.opaque,
self.view.contentScaleFactor);
先把UIView转成UIImage
最後再用CGImageCreateWithImageInRect截图
CGImageRef shotImageRef = CGImageCreateWithImageInRect(image.CGImage,
CGRectMake(200, 200, 100, 100));
※ 编辑: whitefur 来自: 111.243.96.17 (10/18 13:04)
※ 编辑: whitefur 来自: 111.243.96.17 (10/18 13:07)
※ 编辑: whitefur 来自: 111.243.96.17 (10/18 13:08)