fix: Fix potential bug in Photo Orientation (#1765)
This commit is contained in:
parent
6dd1d4147e
commit
eddb01fda1
@ -57,9 +57,10 @@ class PhotoCaptureDelegate: NSObject, AVCapturePhotoCaptureDelegate {
|
|||||||
let exif = photo.metadata["{Exif}"] as? [String: Any]
|
let exif = photo.metadata["{Exif}"] as? [String: Any]
|
||||||
let width = exif?["PixelXDimension"]
|
let width = exif?["PixelXDimension"]
|
||||||
let height = exif?["PixelYDimension"]
|
let height = exif?["PixelYDimension"]
|
||||||
let exifOrientation = photo.metadata[kCGImagePropertyOrientation as String] as? Int ?? 0
|
let exifOrientation = photo.metadata[String(kCGImagePropertyOrientation)] as? UInt32 ?? CGImagePropertyOrientation.up.rawValue
|
||||||
let orientation = getOrientation(forExifOrientation: exifOrientation)
|
let cgOrientation = CGImagePropertyOrientation(rawValue: exifOrientation) ?? CGImagePropertyOrientation.up
|
||||||
let isMirrored = getIsMirrored(forExifOrientation: exifOrientation)
|
let orientation = getOrientation(forExifOrientation: cgOrientation)
|
||||||
|
let isMirrored = getIsMirrored(forExifOrientation: cgOrientation)
|
||||||
|
|
||||||
promise.resolve([
|
promise.resolve([
|
||||||
"path": tempFilePath,
|
"path": tempFilePath,
|
||||||
@ -86,24 +87,24 @@ class PhotoCaptureDelegate: NSObject, AVCapturePhotoCaptureDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getOrientation(forExifOrientation exifOrientation: Int) -> String {
|
private func getOrientation(forExifOrientation exifOrientation: CGImagePropertyOrientation) -> String {
|
||||||
switch exifOrientation {
|
switch exifOrientation {
|
||||||
case 1, 2:
|
case .up, .upMirrored:
|
||||||
return "portrait"
|
return "portrait"
|
||||||
case 3, 4:
|
case .down, .downMirrored:
|
||||||
return "portrait-upside-down"
|
return "portrait-upside-down"
|
||||||
case 5, 6:
|
case .left, .leftMirrored:
|
||||||
return "landscape-left"
|
return "landscape-left"
|
||||||
case 7, 8:
|
case .right, .rightMirrored:
|
||||||
return "landscape-right"
|
return "landscape-right"
|
||||||
default:
|
default:
|
||||||
return "portrait"
|
return "portrait"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getIsMirrored(forExifOrientation exifOrientation: Int) -> Bool {
|
private func getIsMirrored(forExifOrientation exifOrientation: CGImagePropertyOrientation) -> Bool {
|
||||||
switch exifOrientation {
|
switch exifOrientation {
|
||||||
case 2, 4, 5, 7:
|
case .upMirrored, .rightMirrored, .downMirrored, .leftMirrored:
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
|
Loading…
Reference in New Issue
Block a user