A value describing the intended display orientation for an image.
- iOS 8.0+
- macOS 10.10+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
- Image I/O
Values of this type define the position of the pixel coordinate origin point (
0,0) and the directions of the coordinate axes relative to the intended display orientation of the image. Orientation values are commonly found in image metadata, and specifying image orientation correctly can be important both for displaying the image and for certain image processing tasks such as face recognition.
For example, the pixel data for an image captured by an iOS device camera is encoded in the camera sensor's native landscape orientation. When the user captures a photo while holding the device in portrait orientation, iOS writes an orientation value of
CGImage in the resulting image file. Software displaying the image can then, after reading that value from the file's metadata, apply a 90° clockwise rotation to the image data so that the image appears in the photographer's intended orientation.
Compatibility with UIImageOrientation
CGImage type covers the same set of orientation names available in from the
UIImage type, but the underlying numeric values of each type do not match. (For example, the "left mirrored" orientation has an underlying value of 5 in
CGImage, but an underlying value of 7 in
UIImage.) If you have an orientation value in one type and need a semantically equivalent value in the other, use a function such as those below to produce the same-named value in the other type:
Working with Raw TIFF/Exif Numeric Values
Some APIs describe image orientation with basic integer values, intended for interpretation according to the TIFF and Exif specifications. The
CGImage type simply defines symbolic names for those values, so you can convert to and from the raw numeric type with the inherited
init(raw initializer and