以编程方式裁剪屏幕截图
问题描述:
我想通过编程方式截取屏幕截图并通过电子邮件发送。我可以执行此操作,但是这里附有电子邮件的完整屏幕截图,但是我想裁剪发送的屏幕截图。
我该怎么做请建议我这样做。
I want to take screen shot through programmatically and send with Email. I am able to do this but here full screenshot attached with email but I want to crop the screen shot for sending. How can I do this Please suggest me to do this.
这是我的屏幕截图代码。
Here is my code for taking screen shot.
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
答
我用它来裁剪底部的屏幕截图- 40是从底部开始40像素的裁剪屏幕截图。
I used this to crop screen shot from bottom here -40 is crop screenshot by 40 pixels from bottom.
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();