Conditionally adding pipeline elements
View as MarkdownThis sample demonstrates how to conditionally add elements to a pipeline based on the properties of the input image. It shows how to create thumbnails in the sRGB color space with a specified DPI value.
You can read more information about pipelines in the documentation.
Code Snippet
// Create an empty pipeline.
var pipeline = new Pipeline();
// Add a reader as the first element.
var reader = ImageReader.Create("Venice.jpg");
pipeline.Add(reader);
// Add a resize transform.
pipeline.Add(new Resize(320, 0, ResizeInterpolationMode.High));
// Assume that we want thumbnails only in RGB format.
// The order here affects performance because a color converter placed after the down-resizer has less data to process.
if (reader.PixelFormat != PixelFormat.Format24bppRgb)
{
var colorConverter = new ColorConverter(PixelFormat.Format24bppRgb)
{
DestinationProfile = ColorProfile.FromSrgb(),
};
pipeline.Add(colorConverter);
}
// We also want the DPI to be equal to 72.
if (reader.DpiX != 72 || reader.DpiY != 72)
{
pipeline.Add(new ResolutionModifier(72, 72));
}
// Add the JPEG writer.
pipeline.Add(ImageWriter.Create("thumbnail_in_srgb.jpg"));
try
{
// Run the pipeline.
pipeline.Run();
}
finally
{
// Dispose all elements in the pipeline.
pipeline.DisposeAllElements();
}
Input
Venice.jpg
Output
thumbnail_in_srgb.jpg
Used APIs
- Aurigma.GraphicsMill.Codecs.ImageReader
- Aurigma.GraphicsMill.Codecs.ImageReader.Create(String)
- Aurigma.GraphicsMill.Codecs.ImageReader.DpiX
- Aurigma.GraphicsMill.Codecs.ImageReader.DpiY
- Aurigma.GraphicsMill.Codecs.ImageReader.PixelFormat
- Aurigma.GraphicsMill.Codecs.ImageWriter
- Aurigma.GraphicsMill.Codecs.ImageWriter.Create(String)
- Aurigma.GraphicsMill.ColorProfile
- Aurigma.GraphicsMill.ColorProfile.FromSrgb
- Aurigma.GraphicsMill.Transforms.ColorConverter
- Aurigma.GraphicsMill.Transforms.ColorConverter.DestinationProfile
- Aurigma.GraphicsMill.Transforms.Resize
- Aurigma.GraphicsMill.Transforms.ResizeInterpolationMode
- Aurigma.GraphicsMill.Transforms.ResolutionModifier