UIGraphicsBeginImageContext如何设置位置?

时间:2011-12-15 08:35:39

标签: iphone objective-c xcode screenshot

我在我的应用程序中截取屏幕截图。我可以截取屏幕截图,但现在 我想通过指定x和y坐标来实现它。我的意思是从y = 40拍摄截图。这可能吗?

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

1 个答案:

答案 0 :(得分: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();