裁剪屏幕以编程方式拍摄

时间:2011-09-12 12:42:43

标签: cocoa-touch uiimage

我想以编程方式拍摄屏幕截图并通过电子邮件发送。我能够做到这一点,但这里附有电子邮件的完整截图,但我想裁剪发送的屏幕截图。 我怎么能这样做请建议我这样做。

以下是我拍摄屏幕截图的代码。

UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

1 个答案:

答案 0 :(得分:3)

我用这个从底部裁剪屏幕截图-40是裁剪截图,距底部40像素。

UIGraphicsBeginImageContext(self.view.bounds.size);
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(c,-40,0);    // <-- shift everything up by 40px when drawing.
[self.view.layer renderInContext:c];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();