PeachImage

PeachImage.Image

Image.ApplyOrientation Method

Overloads  
ApplyOrientation(ImageOrientation) Returns this image with orientation applied to its pixels, so that an image whose metadata asks to be displayed rotated or mirrored (see Orientation) comes out upright. As a new Image (or this same instance, unchanged, for Normal -- the “may return this” contract Resize(int, int, ResizeOptions) documents, including its disposal implications). Does not modify this instance otherwise.
ApplyOrientation(ImageOrientation, Image) Writes this image with orientation applied to destination, without allocating: the pixel work of ApplyOrientation(ImageOrientation) into an image the caller already owns (for example one rented once and reused across a batch). This image is not modified.

Image.ApplyOrientation(ImageOrientation) Method

Returns this image with orientation applied to its pixels, so that an image whose metadata asks to be displayed rotated or mirrored (see Orientation) comes out upright. As a new Image (or this same instance, unchanged, for Normal -- the “may return this” contract Resize(int, int, ResizeOptions) documents, including its disposal implications). Does not modify this instance otherwise.

public PeachImage.Image ApplyOrientation(PeachImage.ImageOrientation orientation);

Parameters

orientation ImageOrientation

Returns

Image

Exceptions

System.ArgumentOutOfRangeException
orientation is not a defined orientation.

Remarks

Each ImageOrientation names the transform applied to the stored pixels to display them upright, so Rotate90 rotates clockwise. The four orientations that swap width and height produce an image of Height x Width, with the horizontal and vertical resolution swapped to match. Resolution and embedded profiles carry over to the result; an EXIF profile is copied with its orientation tag reset to 1, so a viewer that honours the tag doesn’t transform the already-upright pixels again (this image’s own profile is left as it is). Orientation recorded elsewhere, such as in XMP, is not rewritten. Every PixelFormat is supported.

Image.ApplyOrientation(ImageOrientation, Image) Method

Writes this image with orientation applied to destination, without allocating: the pixel work of ApplyOrientation(ImageOrientation) into an image the caller already owns (for example one rented once and reused across a batch). This image is not modified.

public void ApplyOrientation(PeachImage.ImageOrientation orientation, PeachImage.Image destination);

Parameters

orientation ImageOrientation

The orientation to apply.

destination Image

A different image with the same PixelFormat and dimensions of Width x Height, or Height x Width for the orientations that swap them.

Exceptions

System.ArgumentOutOfRangeException
orientation is not a defined orientation.

System.ArgumentNullException
destination is null.

System.ArgumentException
destination is this image or shares its pixel buffer (the transform cannot be done while reading from the pixels it overwrites -- use ApplyOrientationInPlace(ImageOrientation)), or its pixel format or dimensions don’t match.

Remarks

Only pixels are written; destination’s Metadata, HasAlpha and IsAnimated are left as they are, because carrying this image’s across would allocate. A caller that copies an EXIF profile over should reset its orientation tag itself.