public static void RenderShapeToStream(string dataDir, Shape shape)
{
// ExStart:RenderShapeToStream
ShapeRenderer r = new ShapeRenderer(shape);
// Define custom options which control how the image is rendered. Render the shape to the vector format EMF.
ImageSaveOptions imageOptions = new ImageSaveOptions(SaveFormat.Jpeg)
{
// Output the image in gray scale
ImageColorMode = ImageColorMode.Grayscale,
// Reduce the brightness a bit (default is 0.5f).
ImageBrightness = 0.45f
};
dataDir = dataDir + "TestFile.RenderToStream_out.jpg";
FileStream stream = new FileStream(dataDir, FileMode.Create);
// Save the rendered image to the stream using different options.
r.Save(stream, imageOptions);
// ExEnd:RenderShapeToStream
Console.WriteLine("\nShape rendered to stream successfully.\nFile saved at " + dataDir);
}