Diagram > Diagram DOM > Drawings > Export > Drawing Raster Image Exporter |
The NDrawingRasterImageExporter lets you export the content of the active page (or portions of it) to a raster image in the following file formats: PNG, JPEG and BMP.
The following code shows a save image file dialog that allows the user to create an image from the active page content:
Saving with Dialog |
Copy Code
|
---|---|
NDrawingRasterImageExporter imageExporter = new NDrawingRasterImageExporter(drawingView.Document);
imageExporter.SaveAsImage(drawingView.ActivePage.Bounds, NRaster.DefaultResolution);
|
To save the exported image directly to a file or a stream, you should use the SaveToFile or SaveToStream methods respectively. The following piece of code exports the active page of a drawing document to a file:
Saving to File |
Copy Code
|
---|---|
NDrawingRasterImageExporter imageExporter = new NDrawingRasterImageExporter(drawingView.Document); imageExporter.SaveToFile(@"C:\MyImage.png", drawingView.ActivePage.Bounds, NRaster.DefaultResolution); |
To generate an image on the fly without saving it, you should use the CreateImage method:
Generating Image |
Copy Code
|
---|---|
NDrawingRasterImageExporter imageExporter = new NDrawingRasterImageExporter(drawingView.Document);
NImage image = imageExporter.CreateImage(drawingView.ActivePage.Bounds, NRaster.DefaultResolution);
|
To copy the image to the clipboard, you should use the CopyToClipboard method:
Generating Image |
Copy Code
|
---|---|
NDrawingRasterImageExporter imageExporter = new NDrawingRasterImageExporter(drawingView.Document);
imageExporter.CopyToClipboard(drawingView.ActivePage.Bounds, NRaster.DefaultResolution);
|