fix: ICC profile losing during media compression issue

This commit is contained in:
CMK 2022-05-24 16:04:04 +08:00
parent c21b6e6a89
commit 16365d5d09
1 changed files with 5 additions and 2 deletions

View File

@ -41,7 +41,7 @@ extension ItemProviderLoader {
guard let source = CGImageSourceCreateWithURL(url as CFURL, sourceOptions) else { guard let source = CGImageSourceCreateWithURL(url as CFURL, sourceOptions) else {
return return
} }
#if APP_EXTENSION #if APP_EXTENSION
let maxPixelSize: Int = 4096 // not limit but may upload fail let maxPixelSize: Int = 4096 // not limit but may upload fail
#else #else
@ -87,8 +87,11 @@ extension ItemProviderLoader {
return (utType as String) == UTType.png.identifier return (utType as String) == UTType.png.identifier
}() }()
let sourceProperties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as NSDictionary?
let destinationProperties = [ let destinationProperties = [
kCGImageDestinationLossyCompressionQuality: isPNG ? 1.0 : 0.75 kCGImageDestinationLossyCompressionQuality: isPNG ? 1.0 : 0.75,
kCGImagePropertyProfileName: sourceProperties?[kCGImagePropertyProfileName],
kCGImagePropertyColorModel: sourceProperties?[kCGImagePropertyColorModel]
] as CFDictionary ] as CFDictionary
CGImageDestinationAddImage(imageDestination, cgImage, destinationProperties) CGImageDestinationAddImage(imageDestination, cgImage, destinationProperties)