如何使用objective-c捕获iOS屏幕截图的子集?

问题描述:

我有一个快速的问题。如何在iOS设备上使用objective-c捕获整个屏幕的子集?如何使用objective-c捕获iOS屏幕截图的子集?

我发现下面的代码:

UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow]; 
UIGraphicsBeginImageContext(screenWindow.frame.size); 
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()] 
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); 

伟大的工程,但我只想从一块整个窗口的创建图像。我会怎么做呢?

任何指针将不胜感激!

谢谢。

+0

可能重复[作物截屏编程方式(http://stackoverflow.com/questions/7388047/crop-screen-shot-programatically) – 2012-04-03 23:06:53

+0

我觉得你刚才指定UIGraphicsBeginImageContext不同的大小。然后你可以做翻译来将该帧定位在视图的期望部分上。 – 2012-04-03 23:08:56

取代

UIGraphicsBeginImageContext(screenWindow.frame.size);

UIGraphicsBeginImageContext(CGSizeMake(宽度,高度));的

+0

是假设x和y在(0,0)?如果图像说(50,50),我想要拍摄中心的屏幕截图? – thiesdiggity 2012-04-03 23:47:08

+0

@thiesdiggity - 如果我理解正确,那就是你做翻译的地方。但请参阅http://developer.apple.com/library/ios/documentation/uikit/reference/UIKitFunctionReference/UIKitFunctionReference.pdf – 2012-04-04 00:24:39

+0

如果他们回答了您的问题,请记住接受答案。 – Greg 2012-04-10 02:14:03