I need to convert a RAW image to JPEG and then apply some calculations to the image.
I need the image in both CGImage and UIImage formats.
For some reason, image resolution is correct when it comes to UIImage, but for underlying CGImage resolution is 3x too big.
Why does that happen? How can I make the correct size for CGImage?
// original RAW image: (3504.0, 2336.0)
let imageUrl = Bundle.main.url(forResource: "IMG_3136", withExtension: "CR2")!
let ciImage = CIFilter(imageURL: imageUrl).outputImage!
let uiImage = UIImage(ciImage: ciImage)
let data = uiImage.jpegData(compressionQuality: 0.92)!
let recreatedUiImage = UIImage(data: data, scale: UIScreen.main.scale)!
let cgImage = recreatedUiImage.cgImage!
let cgImageSize = CGSize(width: cgImage.width, height: cgImage.height)
print(recreatedUiImage.size) // (3504.0, 2336.0) CORRECT
print(cgImageSize) // (10512.0, 7008.0) WRONG