Enum JpegTransformEdges
What a lossless transform does with the blocks at the right or bottom edge when the image is not a whole number of MCUs (8 or 16 pixels) across or down, so those blocks cannot move to the other side intact.
public enum JpegTransformEdges
Fields
Keep = 2Leaves partial MCUs where they are, unmirrored, as
jpegtrandoes by default: every pixel is kept, but a strip up to 15 pixels wide at the edge is not turned with the rest.Strict = 1Throws InvalidOperationException when a partial MCU would have to move, as
jpegtran -perfectdoes, so the result is always exact and full size.Trim = 0Drops the partial MCU from an edge that is mirrored, so the image loses up to 15 pixels there (up to 7 for gray), as
jpegtran -trimdoes. Edges that stay in place keep every pixel.
Examples
// Turns the photo upright by its EXIF orientation without re-encoding: no quality is lost, and the tag is reset.
JpegTransform.Apply("sideways.jpg", "upright.jpg", new JpegTransformOptions { Operation = JpegTransformOperation.AutoOrient });
// Rotates, crops and drops the color in one pass; a file can be transformed in place.
JpegTransformResult result = JpegTransform.Apply("upright.jpg", "upright.jpg", new JpegTransformOptions
{
Operation = JpegTransformOperation.Rotate90,
Crop = new Rect(0, 0, 200, 120),
Grayscale = true,
});
Console.WriteLine($"{result.Width} × {result.Height}");