A DGN file is a MicroStation drawing, which is awkward to hand to a designer who works in Photoshop. In this tutorial, you will convert a DGN drawing to a PSD file from a C# application using Aspose.CAD for .NET, so the result opens directly in Photoshop. The conversion takes four steps and a few lines of code.
If you work in Python, we covered the same task in Convert Drawing to Photoshop in Python. This post is for .NET developers.
Online tool or API: which should you use?
Use the free online CAD apps when you have one or two files to convert. You upload the drawing, run the conversion, and download the result. No code is needed.
Use the API when conversion is part of an application, a batch job, a document pipeline, or a feature in your own product. The rest of this post covers the API.
Install Aspose.CAD for .NET
Add the package from NuGet. In Visual Studio, search for Aspose.CAD in the NuGet Package Manager, or run this in the Package Manager Console:
PM> Install-Package Aspose.CAD You can also download the DLL from the Aspose.CAD for .NET releases page and reference it in your project.
Convert a DGN file to PSD in C
The conversion follows four steps:
- Load the DGN file with
Image.Load. - Create a
CadRasterizationOptionsobject and set the page width and height. - Create a
PsdOptionsobject and assign the rasterization options to itsVectorRasterizationOptionsproperty. - Call
Image.Savewith the output path and thePsdOptionsobject.
using Aspose.CAD; using Aspose.CAD.ImageOptions; string sourcePath = "drawing.dgn"; string outputPath = "drawing.psd"; // Load the DGN drawing using (Image image = Image.Load(sourcePath)) { // Define how the vector drawing is rendered to pixels var rasterizationOptions = new CadRasterizationOptions { PageWidth = 1200, PageHeight = 1200 }; // Set PSD as the output format and attach the rasterization options var psdOptions = new PsdOptions { VectorRasterizationOptions = rasterizationOptions }; // Save the drawing as a PSD file image.Save(outputPath, psdOptions); } This sample uses top-level statements, so it runs as-is in a .NET 6 or later console project. In an older project, place the code inside a Main method.
What each part does
-
Image.Loadopens the DGN file. Wrapping it in ausingblock releases the file handle when the conversion finishes. -
CadRasterizationOptionscontrols how the vector drawing is rendered. A PSD file is a raster format, so the drawing has to be converted to pixels, andPageWidthandPageHeightset the size of that rendering. -
PsdOptionstellsSaveto write a PSD file. ItsVectorRasterizationOptionsproperty is where the rasterization settings are applied. -
Image.Savewrites the PSD to the path you provide.
Check the result
Run the program, then open drawing.psd in Photoshop. You should see your drawing rendered as an image at the page size you set. Because the drawing is rasterized, individual CAD entities are not editable as vectors in Photoshop.
If the output looks cropped, too small, or too coarse, adjust PageWidth and PageHeight and run the conversion again. Keep in mind that PSD has size limits: the format supports a maximum of 30,000 pixels in height and width and a 2 GB file size.
Get a temporary license
To try the API without evaluation restrictions, request a free temporary license and apply it before loading your files.
Next steps
Try the sample on one of your own DGN files, then adjust the page size until the PSD matches what your designers need. To explore other output formats and rasterization settings, see the Aspose.CAD for .NET documentation and the API reference. If you want PDF output instead, read Convert DGN to PDF in C#. Questions are welcome on the Aspose.CAD free support forum.
FAQ
How do I convert DGN to PSD in C#? Load the DGN with Image.Load, set PageWidth and PageHeight on a CadRasterizationOptions object, assign it to the VectorRasterizationOptions property of a PsdOptions object, and call Image.Save.
Do I need AutoCAD or Photoshop installed? Aspose describes this conversion as working without AutoCAD or other rendering software. You only need Photoshop, or another PSD-capable editor, to open the result.
Can I convert without writing code? Yes. The free online CAD apps convert files in the browser.
