How to create a black UIImage?

后端 未结 5 1095
无人共我
无人共我 2021-02-08 21:42

I\'ve looked around everywhere, but I can\'t find a way to do this. I need to create a black UIImage of a certain width and height (The width and height change, so I can\'t just

5条回答
  •  一向
    一向 (楼主)
    2021-02-08 22:12

    Here is an example that creates a black UIImage that is 1920x1080 by creating it from a CGImage created from a CIImage:

    let frame = CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: 1920, height: 1080))
    let cgImage = CIContext().createCGImage(CIImage(color: .black()), from: frame)!
    let uiImage = UIImage(cgImage: cgImage)
    

提交回复
热议问题