【问题标题】:I can't display my image in swift 3?我无法在 swift 3 中显示我的图像?
【发布时间】:2017-01-10 23:30:27
【问题描述】:

这是我的原始代码。

在这种情况下,在 imageview 中显示我的图像。

let cgImge = self.test.image?.cgImage?.copy()
self.test.image = UIImage(cgImage: cgImge!, scale: (self.test.image?.scale)!, orientation: (self.test.image?.imageOrientation)!)

这是我在一个项目过程中的代码。

...
UIGraphicsBeginImageContext((self.test.image?.size)!)
self.test.layer.render(in: UIGraphicsGetCurrentContext()!)
self.test.image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
let cgImge = self.test.image?.cgImage?.copy()
self.test.image = UIImage(cgImage: cgImge!, scale: (self.test.image?.scale)!, orientation: (self.test.image?.imageOrientation)!)

...

但我无法显示我的图像。 我可以做些什么来解决这个问题?

【问题讨论】:

    标签: swift3 uigraphicscontext


    【解决方案1】:

    这是我的固定代码。

    UIGraphicsBeginImageContextWithOptions(self.test.bounds.size, self.test.isOpaque, 0.0)
    //UIGraphicsBeginImageContext((self.test.image?.size)!)
    self.test.layer.render(in: UIGraphicsGetCurrentContext()!)
    //self.test.image?.draw(at: self.test.frame)
    let temp: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
    UIGraphicsEndImageContext()
    
    UIGraphicsBeginImageContextWithOptions(self.test.bounds.size, self.test.isOpaque, 1.0)
    temp.draw(in: self.test.bounds)
    let custom: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
    UIGraphicsEndImageContext()
    
    let cgImge = custom.cgImage?.copy(maskingColorComponents: [222,255,222,255,222,255])
    self.test.image = UIImage(cgImage: cgImge!, scale: (self.test.image?.scale)!, orientation: (self.test.image?.imageOrientation)!)
    

    我有一个参考链接

    iOS : Save image with custom resolution

    【讨论】:

      猜你喜欢
      • 2016-06-28
      • 1970-01-01
      • 1970-01-01
      • 2021-09-04
      • 2015-05-01
      • 2020-10-04
      • 1970-01-01
      • 2013-03-24
      • 1970-01-01
      相关资源
      最近更新 更多