06/22 Fix Low impact items
This commit is contained in:
@@ -527,8 +527,15 @@ struct CameraPickerView: UIViewControllerRepresentable {
|
||||
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]
|
||||
) {
|
||||
if let img = info[.originalImage] as? UIImage {
|
||||
parent.image = img
|
||||
parent.onSelected(img)
|
||||
// UIImagePickerController with .camera source delivers images whose
|
||||
// imageOrientation reflects the physical device orientation at capture
|
||||
// time. On iPad in landscape the raw UIImage is rotated 90° relative
|
||||
// to what the user sees in the viewfinder. Drawing into a new context
|
||||
// at the display size bakes the transform into the pixel buffer,
|
||||
// producing a correctly-oriented image regardless of how it was held.
|
||||
let normalised = img.normalised()
|
||||
parent.image = normalised
|
||||
parent.onSelected(normalised)
|
||||
}
|
||||
picker.dismiss(animated: true)
|
||||
}
|
||||
@@ -715,3 +722,23 @@ struct TableFieldView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UIImage orientation normalisation
|
||||
// UIImagePickerController delivers camera photos whose imageOrientation encodes
|
||||
// the device tilt at capture time. Consumers (savePhotoToDisk, PDF generator,
|
||||
// issue thumbnails) all call .jpegData() which honours the EXIF orientation —
|
||||
// but some downstream renderers (UIGraphicsImageRenderer, PDF drawing) ignore it
|
||||
// and display the raw rotated pixels. This extension bakes the orientation
|
||||
// transform into the pixel buffer so all consumers see an upright image.
|
||||
|
||||
extension UIImage {
|
||||
/// Returns a copy of the image with imageOrientation == .up, redrawing
|
||||
/// the pixels into a new context if the orientation is not already correct.
|
||||
func normalised() -> UIImage {
|
||||
guard imageOrientation != .up else { return self }
|
||||
let renderer = UIGraphicsImageRenderer(size: size)
|
||||
return renderer.image { _ in
|
||||
draw(in: CGRect(origin: .zero, size: size))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user