CGImageSourceCreateThumbnailAtIndex() returning wrong width or height resolution
I downsample images using the below code. In the case of 300 dpi JPEG images, the obtained a resized image whose metadata contain a DPIWidth of 300 dpi as expected but a DPIHeight of 72 dpi while the resolution should remain unchanged. The resized image therefore looks stretched vertically in a UIImageView.
I encounter this issue with Xcode 15.2 (15C500b) and iOS 17.2.
Does anyone encounter the same issue?
let maxSize = pwgPhotoMaxSizes(rawValue: upload.photoMaxSize)?.pixels ?? Int.max
let resizeOptions = [kCGImageSourceCreateThumbnailFromImageAlways : true,
kCGImageSourceCreateThumbnailWithTransform : true,
kCGImageSourceThumbnailMaxPixelSize : maxSize] as [CFString : Any]
guard let resized = CGImageSourceCreateThumbnailAtIndex(sourceRef, imageIndex,
resizeOptions as CFDictionary) else {
// Could not retrieve primary image
let error = NSError(domain: "…", code: …, userInfo: […)
failure(error)
return
}
iPhone 14 Pro, iOS 17