ios - 在 swift 中渲染 UIImageView 时质量松散

标签 ios swift uiimageview

我正在快速使用下面的代码将 UIImageView 捕获到一张图像中。它可以工作,但图像的质量与 UIImageView 上显示的图像质量不同。有没有办法在捕获此图像时配置质量?

private func getScreenshow(imageView:UIImageView) -> UIImage{

    UIGraphicsBeginImageContext(self.imageView.frame.size)
    let context = UIGraphicsGetCurrentContext()

    imageView.layer.renderInContext(context!)
    let screenShot = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    UIImageWriteToSavedPhotosAlbum(screenShot, nil, nil, nil)
    return screenShot
}

最佳答案

经过一番搜索,我发现了这个问题。我使用下面的代码来替换“UIGraphicsBeginImageContext”并且它有效。

UIGraphicsBeginImageContextWithOptions(self.imageView.frame.size, true, 0)

关于ios - 在 swift 中渲染 UIImageView 时质量松散,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36794024/

相关文章:

ios - 在 Swift 的 spritekit 游戏中定义我的宇宙飞船运动

ios - SpriteKit 防止 Sprite 在没有弹跳的情况下离开屏幕

ios - 获取 iOS 开发人员证书

ios - 缓存 View Controller

ios - 如何阻止 SwiftUI 重新加载我通过 UIViewRepresentable 使用的 WKWebView 页面?

ios - 逐帧动画 UIImageView

iphone - UIImageView 上的 UIButtons 缩放

ios - UILabel 自动换行功能即使有足够的空间供单词使用也能留出空间

iOS Swift 如何创建协议(protocol)实例

ios - viewDidLayoutSubviews中的UIImageView宽度是1000?