Model Disrespects Image Orientation
maustinstar opened this issue · comments
CGImage
has no reference to the capture orientation. This affects the stitching process for images taken on device (screenshots and web-images are unaffected).
Attempted solution in IRIS/ImageTransfer:
UIImage(
// the patch
cgImage: croppedImage,
scale: 1.0,
// attempt to orient the patch by copying the orientation of the original image
orientation: inputImage!.imageOrientation
).draw(in: rect)
This has no effect.
Solution:
extension of UIImage:
func reoriented() -> UIImage {
if self.imageOrientation == .up { return self }
UIGraphicsBeginImageContext(self.size)
self.draw(at: .zero)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image ?? self
}
Reorient every UIImage with any orientation before the transfer.
This writes a new CGImage that is naturally .up
when used in UIImage.