我有一些从互联网上下载的代码,用于将屏幕截图抓取到相机胶卷上,效果很好,这里是:
CGRect screenRect = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.bounds.size.width, self.view.bounds.size.height);
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, screenRect);
[self.view.layer renderInContext:ctx];
UIImage *screenImage = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(screenImage, nil, nil, nil);
UIGraphicsEndImageContext();
一切都适用于 iPhone,但现在我为 iPad 进行了更改,我需要捕获与整个屏幕不同的矩形,所以我指定了一个不同的矩形,如下所示:
CGRect screenRect;
switch (runningOniPad) {
case 0: // running on iPhone..
screenRect = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.bounds.size.width, self.view.bounds.size.height);
break;
default: // yes, running on iPad..
screenRect = CGRectMake(56, 478, 662, 262);
break;
}
好吧,我在相机胶卷中得到的矩形是我指定的 SIZE,但它的原点似乎是(0,0)......也许它是 [self.view.layer renderInContext:ctx];??
如果有人可以提供帮助,我将不胜感激,非常感谢:)