public void Save(string fileName, PixelFormat requestedFormat) { // create a memory stream, setting the initial capacity MemoryStream bufferStream = new MemoryStream(width * height * 3); // save the data to the memory stream Save(bufferStream, requestedFormat); int pos = fileName.LastIndexOf('.'); // grab the file extension string extension = fileName.Substring(pos + 1); // grab the codec for the requested file extension ICodec codec = CodecManager.Instance.GetCodec(extension); // setup the image file information ImageCodec.ImageData imageData = new ImageCodec.ImageData(); imageData.width = width; imageData.height = height; imageData.format = requestedFormat; // reset the stream position bufferStream.Position = 0; // finally, save to file as an image codec.EncodeToFile(bufferStream, fileName, imageData); bufferStream.Close(); }