看板 MacDev 關於我們 聯絡資訊
想在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
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)