ios - 在不损失质量的情况下在 Objective-C 中截取屏幕截图

标签 ios objective-c xcode screenshot

<分区>

我想要实现的是在我的应用程序中截取屏幕截图,它运行良好,但质量很差,而且屏幕截图的尺寸也非常小。我也尝试像裁剪顶部一样裁剪图像的底部,但我看不到可以在何处为底部添加尺寸。有一个更好的方法吗?我正在使用下面的代码:

// Define the dimensions of the screenshot you want to take (the entire screen in this case)
    UIGraphicsBeginImageContext(self.view.bounds.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *sourceImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    //now we will position the image, X/Y away from top left corner to get the portion we want
    UIGraphicsBeginImageContext(self.view.frame.size);
    [sourceImage drawAtPoint:CGPointMake(0, -10)];
    UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(croppedImage,nil, nil, nil);

感谢您的回答。

最佳答案

替换

UIGraphicsBeginImageContext(self.view.bounds.size);

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);

关于ios - 在不损失质量的情况下在 Objective-C 中截取屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24050262/

上一篇:ios - 将保留属性设置为 nil 就足够了吗?

下一篇:ios - Card.io sdk 未读取到期日期

相关文章:

ios - 识别用于在代码中编辑的 Storyboard uibutton

ios - 没有 UIViewAnimationOptionBeginFromCurrentState,UIView 动画无法工作

iphone - 如何设置我的 WebView 加载已经登录的用户-iPhone

ios - 如何点击 Xcode 模拟器上的特定点

ios - 快速地,我如何检测 UILabel 上的按下开始和结束的时间?

ios - 首次从应用商店安装应用时,Firebase 动态链接不起作用

iOS 7 AutoLayout 底部屏幕的粘性按钮

iphone - UIView autoResizing 有时会起作用

ios - NSLog数组描述,不是内存地址

ios - 正则表达式在 XCode 中查找注释代码