Color distortion occurs when pictures are superimposed on each other. What am I doing wrong?
// My pixel struct
struct RGBA: Codable {
var r: UInt8
var g: UInt8
var b: UInt8
var a: UInt8
}
// Creating UIImage by pixels
let rgba = pixels.flatMap({ $0 })
let colorSpace = CGColorSpaceCreateDeviceRGB()
let data = UnsafeMutableRawPointer(mutating: rgba)
let bitmapContext = CGContext(data: data,
width: size.width,
height: size.height,
bitsPerComponent: 8,
bytesPerRow: 4 * size.width,
space: colorSpace,
bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)
guard let image = bitmapContext?.makeImage() else { return nil }
return UIImage(cgImage: image)
I tried using this code but it didn't work
CGBitmapInfo(rawValue: CGBitmapInfo.byteOrder32Big.rawValue | CGImageAlphaInfo.premultipliedLast.rawValue).rawValue)
Thanks


