@@ -58,36 +58,16 @@ final class PhotoCaptureContext: NSObject, AVCapturePhotoCaptureDelegate {
5858 print ( " Error occurred while capturing photo: Missing pixel buffer ( \( String ( describing: error) ) ) " )
5959 return
6060 }
61-
62- var photoFormatDescription : CMFormatDescription ?
63- CMVideoFormatDescriptionCreateForImageBuffer ( allocator: kCFAllocatorDefault, imageBuffer: photoPixelBuffer, formatDescriptionOut: & photoFormatDescription)
64-
65- var orientation : UIImage . Orientation = . right
66- if self . orientation == . landscapeLeft {
67- orientation = . down
68- } else if self . orientation == . landscapeRight {
69- orientation = . up
70- } else if self . orientation == . portraitUpsideDown {
71- orientation = . left
72- }
73-
74- let finalPixelBuffer = photoPixelBuffer
75- let renderedCIImage = CIImage ( cvImageBuffer: finalPixelBuffer)
76- if let cgImage = self . ciContext. createCGImage ( renderedCIImage, from: renderedCIImage. extent) {
77- var image = UIImage ( cgImage: cgImage, scale: 1.0 , orientation: orientation)
78- if image. imageOrientation != . up {
79- UIGraphicsBeginImageContextWithOptions ( image. size, true , image. scale)
80- if self . mirror, let context = UIGraphicsGetCurrentContext ( ) {
81- context. translateBy ( x: image. size. width / 2.0 , y: image. size. height / 2.0 )
82- context. scaleBy ( x: - 1.0 , y: 1.0 )
83- context. translateBy ( x: - image. size. width / 2.0 , y: - image. size. height / 2.0 )
84- }
85- image. draw ( in: CGRect ( origin: . zero, size: image. size) )
86- if let currentImage = UIGraphicsGetImageFromCurrentImageContext ( ) {
87- image = currentImage
88- }
89- UIGraphicsEndImageContext ( )
90- }
61+
62+ //if let value = photo.metadata[kCGImagePropertyOrientation as String] as? NSNumber {
63+ // orientation = value.int32Value
64+ //} else {
65+ let orientation = exifOrientation ( for: self . orientation, mirror: self . mirror)
66+ //}
67+
68+ let ci = CIImage ( cvImageBuffer: photoPixelBuffer) . oriented ( forExifOrientation: orientation)
69+ if let cgImage = self . ciContext. createCGImage ( ci, from: ci. extent) {
70+ let image = UIImage ( cgImage: cgImage, scale: 1.0 , orientation: . up)
9171 self . pipe. putNext ( . finished( image, nil , CACurrentMediaTime ( ) ) )
9272 } else {
9373 self . pipe. putNext ( . failed)
0 commit comments