DWG and DXF are the popular file formats used to store data as well as metadata of the CAD designs. However, it is not possible to directly view or display CAD designs by embedding DWG and DXF files within your web or desktop applications. One of the feasible solutions is CAD to image conversion. This article aims to show you how to convert DWG/DXF files to PNG, JPEG, BMP, TIFF, and GIF images using C#.
- C# DWG or DXF Converter API
- C# DWG or DXF to PNG Conversion
- DWG or DXF to JPG Conversion in C#
- Convert DXG or DXF to BMP, GIF, and TIFF in C#
Info: Aspose Text to GIF converter allows you to create fun animations just by typing.
C# DWG or DXF to Image Converter API
Aspose.CAD for .NET is a CAD manipulation API that lets you process and convert CAD files using C# or VB.NET. The API provides easy to use methods to convert DWG/DXF designs to raster image formats within a few lines of code. You can download the API or install it within your .NET applications using NuGet.
C# DWG or DXF to PNG Conversion
The following are the steps to convert a DWG or DXF file to PNG image using Aspose.CAD for .NET.
- Load the DWG/DXF file using Image class.
- Create an object of CadRasterizationOptions class and set the height and width of the resultant image.
- Create an object of PngOptions class.
- Set PngOptions.VectorRasterizationOptions to CadRasterizationOptions object.
- Convert CAD to PNG using Image.Save(String, ImageOptionsBase) method.
The following code sample shows how to convert a DWG file to PNG using C#.
DWG or DXF to JPG C# Conversion
Similar to DWG/DXF to PNG conversion, you can convert the CAD drawings to the JPEG image using Aspose.CAD for .NET. The following are the steps to perform this operation.
- Use the Image class to load the DWG/DXF file.
- Create an object of CadRasterizationOptions class and set the height and width of the resultant image.
- Create an object of JpegOptions class.
- Set JpegOptions.VectorRasterizationOptions to CadRasterizationOptions object.
- Convert CAD to JPEG using Image.Save(String, ImageOptionsBase) method.
The following code sample shows how to convert CAD DWG/DXF file to JPG using C#.
DXG or DXF to BMP, TIFF, and GIF using C#
In order to convert the DWG/DXF files into BMP, TIFF, or GIF images, you can follow the same steps that you have used above. The only modification would be the usage of GifOptions, TiffOptions, and BmpOptions classes for conversion to GIF, TIFF, and BMP images respectively. The following code sample shows how to convert a DWG or DXF file to a GIF, TIFF, and BMP image using C#.
Conclusion
In this article, you have learned how to convert CAD’s DXG or DXF files to PNG, JPEG, BMP, TIFF, and GIF images using C#. Furthermore, you have seen how to set the height and width of the resultant raster image in CAD to image conversion. You can explore more about Aspose’s CAD file manipulation API using the documentation.