Class JpegTransformOptions
Options for JpegTransform: the rotation or flip, a crop, dropping color, how partial edge blocks are handled, how the result is coded and whether metadata is copied. The defaults copy the image unchanged, with optimized Huffman tables.
public sealed class JpegTransformOptions
- Inheritance
-
JpegTransformOptions
- Inherited Members
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}");
Properties
Arithmetic
Gets whether the result is arithmetic-coded (jpegtran -arithmetic; SOF9, or SOF10 with Progressive), as
Arithmetic writes: about 4 to 8% smaller than optimized Huffman tables, with the same
pixels, so a Huffman file can be repacked with no loss; but no web browser reads it. OptimizeHuffman is then
ignored. Defaults to false: Huffman-coded, whatever the source was, as jpegtran does.
public bool Arithmetic { get; init; }
Property Value
CopyMetadata
Gets whether EXIF, ICC, XMP, IPTC, comments and other application segments are copied (jpegtran -copy all).
Defaults to true. EXIF's pixel dimensions follow the result; its thumbnail gets the same rotation, flip
and gray conversion, and is dropped after a crop, since it would still show the whole image. With false
only the JFIF or Adobe segment that says how to read the colors is written.
public bool CopyMetadata { get; init; }
Property Value
Crop
Gets the area to keep, in the coordinates of the image after Operation, or null (the
default) for all of it. Its left and top edges move left and up to the MCU grid, as with jpegtran -crop, so the
result can be up to 15 pixels wider and taller than asked; its right and bottom edges are kept as given.
public Rect? Crop { get; init; }
Property Value
- Rect?
Default
Gets the default options: no change, edges trimmed, optimized Huffman tables, metadata copied.
public static JpegTransformOptions Default { get; }
Property Value
Edges
Gets what happens to partial MCUs at a mirrored edge. Defaults to Trim.
public JpegTransformEdges Edges { get; init; }
Property Value
Grayscale
Gets whether the result keeps only the luma component, a gray image with no loss, as jpegtran -grayscale does.
Applies to YCbCr files; gray files are unchanged, and RGB, CMYK and YCCK files throw NotSupportedException.
public bool Grayscale { get; init; }
Property Value
Operation
Gets the rotation or flip. Defaults to None.
public JpegTransformOperation Operation { get; init; }
Property Value
OptimizeHuffman
Gets whether a sequential result gets Huffman tables made for it (jpegtran -optimize), which makes it a few percent
smaller than the standard tables do. Defaults to true, so a transformed file is not larger than its
source for the tables alone. 12-bit files always get their own; progressive ones always do too.
public bool OptimizeHuffman { get; init; }
Property Value
Progressive
Gets whether the result is written progressive, with the scan script and per-scan tables of
Progressive. Defaults to false: sequential, whatever the source was, as
jpegtran does without -progressive.
public bool Progressive { get; init; }