从0,0开始捕获屏幕截图 [英] Capturing of Screen shot starting from 0,0

查看:94
本文介绍了从0,0开始捕获屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码制作屏幕截图

I am using following code to make a screen shot

UIGraphicsBeginImageContext(self.view.frame.size);

blendMode:kCGBlendModeClear alpha:1.0];

[self.view.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

return viewImage;

工作正常,但它返回全屏,我想要一个特定帧的屏幕截图,如(100,100,200,200),我试图进行更改:

It is working fine but it returns the full screen, and I want a screen shot of a particular Frame, like ( 100,100,200,200), I tried to make changes in:

UIGraphicsBeginImageContext(self.view.frame.size);

但没有成功。

推荐答案

试试这个:

float x = 100;
float y = 100;
CGSize size = CGSizeMake(200,200);

UIGraphicsBeginImageContext(size);
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(c, -x, -y);
[view.layer renderInContext:c];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

这篇关于从0,0开始捕获屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆