2011-12-15 140 views
1

我在我的應用程序中截圖。我可以截取屏幕截圖,但現在我想通過指定x和y座標來獲取屏幕截圖。我的意思是從y = 40開始截圖。那可能嗎?UIGraphicsBeginImageContext如何設置位置?

UIGraphicsBeginImageContext(screenshot.frame.size); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
+0

http://stackoverflow.com/a/5538275/1077722 – 2013-05-11 21:30:26

回答

0
UIGraphicsBeginImageContext(screenshot.frame.size); 
CGImageRef imageRef = CGImageCreateWithImageInRect((CGImageRef)self.view.layer.contents, cropRect); 
UIImage *image = [UIImage imageWithCGImage:imageRef]; 
CGImageRelease(imageRef); 
[image drawInRect:CGRectMake(...)]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext();