[問題] UIView特定範圍截圖
想在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
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)
討論串 (同標題文章)
以下文章回應了本文 (最舊先):
完整討論串 (本文為第 1 之 5 篇):
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章