A quick ugly fix for JFIF image orientation bug
We need the `kSDCGImageSourceSkipMetadata`, or the EXIF orientation translated by JFIF stills contains the non-Up side, and apply twice (by Apple's ImageIO and us)
This commit is contained in:
parent
36e484b317
commit
9ff08a1e66
|
@ -27,6 +27,8 @@ static CGImageSourceRef (*SDCGImageGetImageSource)(CGImageRef);
|
|||
|
||||
// Specify File Size for lossy format encoding, like JPEG
|
||||
static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestinationRequestedFileSize";
|
||||
// Avoid ImageIO translate JFIF orientation to EXIF orientation which cause bug because returned CGImage already apply the orientation transform
|
||||
static NSString * kSDCGImageSourceSkipMetadata = @"kCGImageSourceSkipMetadata";
|
||||
|
||||
// This strip the un-wanted CGImageProperty, like the internal CGImageSourceRef in iOS 15+
|
||||
// However, CGImageCreateCopy still keep those CGImageProperty, not suit for our use case
|
||||
|
@ -232,7 +234,7 @@ static CGImageRef __nullable SDCGImageCreateCopy(CGImageRef cg_nullable image) {
|
|||
}
|
||||
}
|
||||
// Parse the image properties
|
||||
NSDictionary *properties = (__bridge_transfer NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source, index, NULL);
|
||||
NSDictionary *properties = (__bridge_transfer NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source, index, (__bridge CFDictionaryRef)@{kSDCGImageSourceSkipMetadata : @(YES)});
|
||||
CGFloat pixelWidth = [properties[(__bridge NSString *)kCGImagePropertyPixelWidth] doubleValue];
|
||||
CGFloat pixelHeight = [properties[(__bridge NSString *)kCGImagePropertyPixelHeight] doubleValue];
|
||||
CGImagePropertyOrientation exifOrientation = (CGImagePropertyOrientation)[properties[(__bridge NSString *)kCGImagePropertyOrientation] unsignedIntegerValue];
|
||||
|
|
Loading…
Reference in New Issue