作者ahchie (啵B劝-福.加油)
看板MacDev
标题Re: [问题] UIView特定范围截图
时间Fri Oct 18 13:08:29 2013
※ 引述《whitefur (白毛)》之铭言:
: 想在UIView上特定区城的做截图
: 目前找到最接近的方法只能截出左上角
: 假设要截取左上角长宽200的区城
: UIGraphicsBeginImageContextWithOptions(CGSizeMake(200, 200), self.view.opaque, self.view.contentScaleFactor);
: CGContextRef context = UIGraphicsGetCurrentContext();
: [self.view.layer renderInContext:context];
: UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
: UIGraphicsEndImageContext();
: 请问该如何截出左上角以外的特定区城呢?
: 感谢
还差一步就可以做到 利用CGImageRef
CGRect rect = CGRectMake( 你想要的rect );
CGImageRef imageRef = \
CGImageCreateWithImageInRect([上面截的UIImage CGImage], rect);
UIImage* croppedImage = [UIImage imageWithCGImage:imageRef
scale:1.0f
orientation:对应的UIImageOrientation];
CGImageRelease(imageRef);
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 1.34.186.156
1F:推 whitefur:我刚已经修文了, 看来你跟我同时回文XD 10/18 13:15
2F:→ ahchie:哈哈 水喔 (Y) 10/18 13:49