What is going on in ImagePicker? What type is Image? The device's camera should give an image a lot smaller than 9072 by 12198.
If you want to support images that large, try CGImageDestination. For example:
struct ImageDestination {
let outputData = CFDataCreateMutable(nil, 0)!
let cgImageDestination: CGImageDestination
init?(type: UTType, count: Int = 1) {
guard let d = CGImageDestinationCreateWithData(outputData, type.identifier as CFString, count, nil)
else { return nil }
self.cgImageDestination = d
}
mutating func addImage(_ image: CGImage) {
CGImageDestinationAddImage(cgImageDestination, image, nil)
}
mutating func finalize() throws {
guard CGImageDestinationFinalize(cgImageDestination) else {
throw DocumentFailure.savingUnknown
}
}
}
/// usage:
let imageCG = uiImage.cgImage!
var dest = ImageDestination(type: .jpeg)!
dest.addImage(imageCG)
dest.finalize()
// your data
dest.outputData
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: