Drawing Raster Image Exporter
In This Topic
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.
Saving with Dialog
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);
|
Saving to File or Stream
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);
|
If you want to directly show a File Save dialog with a specific vector image format selected by default you can pass the file extension of the desired file format to the SaveAsImage method:
Saving with a File Save dialog |
Copy Code
|
NDrawingVectorImageExporter imageExporter = new NDrawingVectorImageExporter(m_DrawingDocument);
imageExporter.SaveAsImage("png");
|
Generating Raster Image
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);
|
Copying to Clipboard
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);
|
See Also