- About Graphics Mill
- What's New?
- Breaking Changes in Graphics Mill 12
- Breaking Changes in Graphics Mill 11
- Features
- Supported File Formats
- System Requirements
- Getting Started
- Working with Image Formats
- Transforming Images (Resize, Rotate, Crop)
- Working with Metadata
- Color Management and Color Reduction
- Drawing Text and Graphics
- Color Keying (Green Screen Removal)
- Channels and Pixel Data
- Color and Tone Correction
- Working with Photoshop (PSD) Files
- Image Filters
- Processing Large Images
- Basics of Image Processing
- Troubleshooting
- Class Library Reference
- Licensing
- End User License Agreement
- Copyright Notices
Disposing Pipeline Elements
All the pipeline elements implement the IDisposable interface, so you can release their resources by calling Dispose(). Although pipeline elements are disposed during garbage collection, the problem is that Garbage Collector might not run for some time. So to make sure that an element's resources are released once you're finished with it, you should manually call the Dispose() method or instantiate the element in the using statement.
using (var reader = new JpegReader(@"Images\in.jpg"))
using (var resizer = new Resize(2048, 0))
using (var writer = new JpegWriter(@"Images\Output\out.jpg"))
{
resizer.InterpolationMode = ResizeInterpolationMode.High;
writer.Exif = reader.Exif;
Pipeline.Run(reader + resizer + writer);
}
In addition to common disposing facilities, Graphics Mill provides two more approaches to dispose of pipeline elements.
Disposing All Elements
You can dispose all elements of a pipeline at once by calling the Pipeline.DisposeAllElements() method. This approach allows you to avoid creating local variables pointing to pipeline elements in order to be able to call the Dispose() method for each of them.
Here is the code to demonstrate this approach:
var pipeline = new Pipeline()
{
ImageReader.Create(@"Images\in.jpg"),
new Resize(2048, 0),
ImageWriter.Create(@"Images\Output\out.jpg")
};
pipeline.Run();
pipeline.DisposeAllElements();
Disposing Inner Elements
Some pipeline elements (i.e. ChannelCombiner) implement properties holding other pipelines. In order to dispose of these inner pipelines, such elements provide AutoDisposeXXX properties specifying whether the inner pipeline should be disposed along with the element.
All the pipeline elements supporting auto-disposing of inner pipelines are listed below.
- ChannelCombiner.AutoDisposeSources is demonstrated in the Reading and Writing Channels topic.
- Combiner.AutoDisposeTopImage is demonstrated in the Transforming Images with Pipelines topic.
- SetAlpha.AutoDisposeAlphaSource is demonstrated in the following code snippet.
using (var alpha = new SetAlpha())
{
alpha.AlphaSource = ImageReader.Create(@"Images\alpha.png");
alpha.AutoDisposeAlphaSource = true;
Pipeline.Run(@"Images\in.jpg" + alpha + @"Images\Output\out.png");
}