Ios 如何在Xcode中捕获屏幕上指定的区域截图

Ios 如何在Xcode中捕获屏幕上指定的区域截图,ios,screenshot,Ios,Screenshot,如何在Xcode中捕获屏幕上指定的区域截图 例如,我希望在屏幕上捕获一个区域(0100320200)并保存到UIImage对象 谢谢请尝试以下代码获取全屏截图(按键窗口) 尝试此代码以本机分辨率捕获UIView CGRect rect = [captureView bounds]; UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f); CGContextRef context = UIGraphicsGetCurrentConte

如何在Xcode中捕获屏幕上指定的区域截图

例如,我希望在屏幕上捕获一个区域(0100320200)并保存到UIImage对象


谢谢

请尝试以下代码获取全屏截图(按键窗口)

尝试此代码以本机分辨率捕获UIView

CGRect rect = [captureView bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[captureView.layer renderInContext:context];   
UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
如果需要的话,这会以jpg格式将UIImage以95%的质量保存在应用程序的文档文件夹中

NSString  *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/capturedImage.jpg"]];    
[UIImageJPEGRepresentation(capturedImage, 0.95) writeToFile:imagePath atomically:YES];

来源:

请尝试以下代码获取全屏截图(关键窗口)

尝试此代码以本机分辨率捕获UIView

CGRect rect = [captureView bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[captureView.layer renderInContext:context];   
UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
如果需要的话,这会以jpg格式将UIImage以95%的质量保存在应用程序的文档文件夹中

NSString  *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/capturedImage.jpg"]];    
[UIImageJPEGRepresentation(capturedImage, 0.95) writeToFile:imagePath atomically:YES];
资料来源: