带参数的UIGraphicsBeginImageContext

带参数的UIGraphicsBeginImageContext

本文介绍了带参数的UIGraphicsBeginImageContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在申请中截取屏幕截图。我可以截取屏幕截图。

I am taking a screenshot in my application. I am able to take the screenshot.

现在我想通过指定x和y坐标来截取屏幕截图。这可能吗?

Now I want to take the screenshot by specifying the x and y coordinate. Is that possible?

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


推荐答案

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

这篇关于带参数的UIGraphicsBeginImageContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 04:02