[問題] UIView特定範圍截圖

看板MacDev作者 (白毛)時間11年前 (2013/10/18 12:47), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/5 (看更多)
想在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

10/18 13:02, , 1F
CGContextMoveToPoint 試一下 換掉cgpoint
10/18 13:02, 1F
自問自答 把上面的第一行改成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)
文章代碼(AID): #1IOBr8K2 (MacDev)
文章代碼(AID): #1IOBr8K2 (MacDev)