Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
954 B
2
Indexable
Never
func genImage() {
        let width = 810
        let height = 1080
        let imgBytes: UnsafeMutableRawPointer = malloc(Int(width * height * 4))
        let colourSpace = CGColorSpaceCreateDeviceRGB()
        
        guard let context = CGContext(data: imgBytes, width: Int(width), height: Int(height), bitsPerComponent: 8, bytesPerRow: Int(width * 4), space: colourSpace, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else {
            free(imgBytes)
            return

        }
        
        let caLayer = CALayer()
        caLayer.backgroundColor = .init(red: 1.0, green: 0.9, blue: 0.5, alpha: 1.0)
        caLayer.frame = CGRect(x: 0, y: 0, width: width, height: height)
//        caLayer.setNeedsDisplay()
        caLayer.draw(in: context)
        
        let data3 = NSData(bytes: imgBytes, length: Int(width * height * 4))
        let outputImage = UIImage(data: data3 as Data)
        
        free(imgBytes)
        
    }