以编程方式裁剪屏幕截图 [英] Crop Screen shot programmatically
本文介绍了以编程方式裁剪屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过编程方式截取屏幕截图并通过电子邮件发送。我可以执行此操作,但是这里附有电子邮件的完整屏幕截图,但是我想裁剪发送的屏幕截图。
我该怎么做请建议我这样做。
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();
这篇关于以编程方式裁剪屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文