I need to process large images (20,000x20,000pixels) in C#. Opening these images directly isn\'t the way to go because of memory limitations, but what I want to do is split
You can use the built-in .Net libraries.
Use
sourceBitmap = (Bitmap)Image.FromStream(sourceFileStream, false, false);
That will stop the image data from being cached in memory. You can create a new destination bitmap to draw a subsection of that massive image to:
var output = new Bitmap(outputWidth, outputHeight);
var outputGraphics = Graphics.FromImage(output);
outputGraphics.DrawImage(sourceBitmap, destRect, srcRect, GraphicsUnit.Pixel);
using (var fs = File.OpenWrite(outputFilePath))
{
output.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
}
Where destRect can be the whole size of the outputImage, or a smaller area.