DGN to JPG, PNG, TIFF

DGN files are two-dimensional or three-dimensional (2D/3D) drawings supported by construction CAD applications. In certain cases, you may need to convert a DGN file to an image for previewing it in different system environments. This article covers how to convert DGN to JPEG, PNG, or TIFF image with all the important details:

DGN to JPEG, PNG, or TIFF Image Converter – C# API Installation

Aspose.CAD for .NET API supports creating, editing, and manipulating DGN files and several other file formats. You can configure the API by downloading the DLL file from the New Releases, or using the following NuGet installation command:

PM> Install-Package Aspose.CAD

Convert DGN File to JPEG Image Programmatically with C#

You can convert a DGN file to a JPEG image with the following steps:

  1. Load input DGN file using the Image class.
  2. Initialize an object of CadRasterizationOptions class.
  3. Create an instance of JpegOptions class.
  4. Convert the DGN to a JPG image with the Save method.

The following code snippet shows how to convert a DGN file to a JPEG image programmatically using C#:

// Load input DGN file using Image class
Image image = Image.Load("template.dgn");
// Initialize an object of CadRasterizationOptions
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions()
{
PageWidth = 1600,
PageHeight = 1600
};
// Create an instance of JpegOptions
JpegOptions options = new JpegOptions();
// Set CadRasterizationOptions properties
options.VectorRasterizationOptions = rasterizationOptions;
// Convert DGN to JPG image
image.Save("output.jpg", options);
view raw DGN-to-JPG.cs hosted with ❤ by GitHub

Convert DGN to PNG Image Programmatically using C#

You can convert a DGN file to a PNG image with the steps below:

  1. Load input DGN file with the Image class.
  2. Create an instance of CadRasterizationOptions and set image height & width.
  3. Create an instance of PngOptions and set VectorRasterizationOptions.
  4. Convert the DGN to a PNG Image using Image.Save method.

The code sample below explains how to convert a DGN file to a PNG image programmatically with C#:

// Load DGN file using Image class
Image image = Image.Load("template.dgn");
// Create an instance of CadRasterizationOptions and set image height & width
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions()
{
PageWidth = 1600,
PageHeight = 1600
};
// Create an instance of PngOptions
PngOptions options = new PngOptions();
// Set the VectorRasterizationOptions property as CadRasterizationOptions
options.VectorRasterizationOptions = rasterizationOptions;
// Convert DGN to PNG Image
image.Save("output.png", options);
view raw DGN-to-PNG.cs hosted with ❤ by GitHub

DGN to TIFF Image Conversion Programmatically in C#

You can convert a DGN file to a TIFF image with the below steps:

  1. Load input DGN file using the Image class.
  2. Initialize an object of CadRasterizationOptions class.
  3. Create an instance of TiffOptions type.
  4. Set the VectorRasterizationOptions property.
  5. Convert the DGN to a TIFF image with the Save method.

The following code snippet shows how to convert a DGN file to a TIFF image programmatically in C#:

// Load input DGN file using Image class
Image image = Image.Load("template.dgn");
// Initialize an object of CadRasterizationOptions
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions()
{
PageWidth = 1600,
PageHeight = 1600
};
// Create an instance of TiffOptions
TiffOptions options = new TiffOptions(FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
// Set the VectorRasterizationOptions property
options.VectorRasterizationOptions = rasterizationOptions;
// Convert DGN to TIFF Image
image.Save("output.tiff", options);
view raw DGN-to-TIFF.cs hosted with ❤ by GitHub

Get Free Temporary License

You can evaluate the API without any limitations by requesting a Free Temporary License.

Conclusion

In this article, you have learned how to convert a DGN file to different image formats like JPEG, PNG, or TIFF programmatically using C#. You can take a look at several other features of the API by visiting the Documentation. In case of any queries, please get in touch with us at the Free Support Forum.

See Also