PeachImage

PeachImage.Image

Image.ConvertTo Method

Overloads  
ConvertTo(PixelFormat) Converts this image to targetFormat, returning a new Image (or this same instance, unchanged, when it already has that format -- the “may return this” contract Resize(int, int, ResizeOptions) documents). Supports every combination of the gray, RGB and RGBA formats at 8-bit, 16-bit and 32-bit float depth, so that, for example, an HDR RgbaF32 JPEG XL decode can be brought to an encodable Rgb24.
ConvertTo(PixelFormat, int, TaskScheduler) Converts to targetFormat with a bound on the threads the conversion may use.

Image.ConvertTo(PixelFormat) Method

Converts this image to targetFormat, returning a new Image (or this same instance, unchanged, when it already has that format -- the “may return this” contract Resize(int, int, ResizeOptions) documents). Supports every combination of the gray, RGB and RGBA formats at 8-bit, 16-bit and 32-bit float depth, so that, for example, an HDR RgbaF32 JPEG XL decode can be brought to an encodable Rgb24.

public PeachImage.Image ConvertTo(PeachImage.PixelFormat targetFormat);

Parameters

targetFormat PixelFormat

Returns

Image

Exceptions

System.NotSupportedException
This image format or targetFormat is not supported (see the remarks for CMYK and YCCK).

System.ArgumentOutOfRangeException
targetFormat is not a defined pixel format.

Remarks

Values are converted as stored: no transfer function, gamut or tone mapping is applied. Integer targets round to the nearest value and clamp to the format range (float values below 0 or above 1 saturate). Colour to gray uses the BT.601 luma weights; a target without alpha discards the alpha channel (colour is not composited onto a background); a source without alpha gets opaque alpha. Resolution and embedded profiles carry over to the result. Cmyk32 and Ycck32 convert to Rgb24, Rgba32 and Gray8 only, with no colour profile: R = 255 x (1 - C) x (1 - K) (likewise G and B, channels scaled to 0..1, 0 meaning no ink), an approximation of how the inks look. YCCK (from DecodeRawYcck) is turned into CMYK first, and the JPEG decoder returns standard CMYK, de-inverting Adobe files, when DecodeRawYcck is off. Nothing converts into CMYK or YCCK. Use ConvertToSrgb() to honour an embedded ICC profile.

Image.ConvertTo(PixelFormat, int, TaskScheduler) Method

Converts to targetFormat with a bound on the threads the conversion may use.

public PeachImage.Image ConvertTo(PeachImage.PixelFormat targetFormat, int maxDegreeOfParallelism, System.Threading.Tasks.TaskScheduler? taskScheduler=null);

Parameters

targetFormat PixelFormat

The pixel format to convert to.

maxDegreeOfParallelism System.Int32

The most threads this call may use: -1 leaves it to the library (up to System.Environment.ProcessorCount), 1 converts on the calling thread. Per call, not global.

taskScheduler System.Threading.Tasks.TaskScheduler

An optional scheduler for the parallel work, to share one limit across concurrent calls. null uses the thread pool.

Returns

Image

Exceptions

System.NotSupportedException
This image format or targetFormat is YCCK.

System.ArgumentOutOfRangeException
targetFormat is not a defined pixel format.