【问题标题】:screenshot is not in proper size IOS屏幕截图大小不合适 IOS
【发布时间】:2016-08-02 06:06:12
【问题描述】:

在我的 IOS 应用程序代码中,我正在截取 UIimageView 的屏幕截图,但是当我截取它时,它并没有被以下代码正确截取。

func captureView() -> UIImage {
//        let rect: CGRect = self.imageView.bounds

        UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, false, 0.0)//add this line

        let context: CGContextRef = UIGraphicsGetCurrentContext()!
        self.view.layer.renderInContext(context)
        let img: UIImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return img
    }

我想要 imageView 中图像的精确屏幕截图,因为上面有更多图像。 请建议我获得准确的 UIImageView 屏幕截图的正确代码

【问题讨论】:

  • 我想要 imageView 中图像的精确屏幕截图,因为上面有更多图像。意味着给我看屏幕截图
  • 这是简单的 imageView.. 我想拍那个..
  • 只是 Imageview 不是全屏
  • 一次尝试这个 imageview.layer.renderInContext(context)
  • 它工作正常,但我需要此图像上的其他图像视图没有出现在屏幕截图中

标签: ios swift image screenshot


【解决方案1】:

如何在UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.mainScreen().scale) 中添加UIScreen.mainScreen().scale 而不是0.0

func captureView() -> UIImage {
            UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.mainScreen().scale)
            drawViewHierarchyInRect(bounds, afterScreenUpdates: true)
            let img = UIGraphicsGetImageFromCurrentImageContext()
            UIGraphicsEndImageContext()
            return img!
        }

【讨论】:

  • 什么是绘制 ViewHierchyinRect()
  • 请查看this
  • 我在问你的方法.. drawViewHierarchyInRect(bounds, afterScreenUpdates: true)
  • 这不是我自己的方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-11
  • 2015-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-22
相关资源
最近更新 更多