如何截取应用程序窗口的一部分的屏幕截图? [英] How to take a screenshot of a part of an app's window?

查看:185
本文介绍了如何截取应用程序窗口的一部分的屏幕截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试保存屏幕视图的屏幕截图,其中所有视图和图层均已合并.我知道如何执行此操作的唯一方法是使用下面的代码.

I'm trying to save a screenshot of a part of the screen with all views and layers merged. The only way I know how to do this is with the code below.

下面的代码创建一个80x80的正方形,但左上角为0,0.

The code below creates an 80x80 square, but with a top left corner at 0,0.

如何从完整的屏幕截图中切出较小的矩形?例如,我有一个320x480的全窗口屏幕截图,但是我只需要一个以160,240为中心的80x80正方形?

How can I cut a smaller rectangle out of a full page screenshot? For example I have a 320x480 full window screenshot, but I only need an 80x80 square centered at 160,240?

UIGraphicsBeginImageContext(smallView.frame.size);
[appDelegate.window.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

谢谢!

推荐答案

在获取截图图像后,使用此裁剪所需部分

after getting the screenshot image crop the required part using this

CGImageRef imageRef = CGImageCreateWithImageInRect([screenshot CGImage], cropRect);
UIImage *result = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);

这篇关于如何截取应用程序窗口的一部分的屏幕截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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