ImageGear .NET v24.12 - Updated
CAD to Image
User Guide > How to Work with... > CAD > How To ... > Convert ... > CAD to Image

The CADViewer sample demonstrates this functionality. See Samples.

The following CADRaster sample illustrates how you can create a raster page from a CAD page:

C#
Copy Code
using System.IO;
using ImageGear.Formats;
using ImageGear.Formats.CAD;

public static void CadToRaster(string path)
{
     ImGearCADPage page = null;

     // Load file.
     using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         page = ImGearFileFormats.LoadPage(fileStream, 0);
     }

     // Get an ImGearRasterPage from the loaded ImGearCADPage
     ImGearRasterPage raster = page.Rasterize();
}
VB.NET
Copy Code
Imports System.IO
Imports ImageGear.Formats
Imports ImageGear.Formats.CAD

Public Sub CadToRaster(path As String) 
    Dim page as ImGearCADPage

    ' Load file.
    Using fileStream as FileStream = New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
        page = ImGearFileFormats.LoadPage(fileStream, 0)
    End Using

    ' Get an ImGearRasterPage from the loaded ImGearCADPage
    Dim raster as ImGearRasterPage = page.Rasterize()
End Sub

 If you simply wish to save your CAD file as an image the following sample shows how this can be done:

C#
Copy Code
using System.IO;
using ImageGear.Formats;
using ImageGear.Formats.CAD;

public static void CadToImage(string inPath, string outPath)
{
    ImGearCADPage page = null;

    // Load file.
    using (FileStream fileStream = new FileStream(inPath, FileMode.Open, FileAccess.Read, FileShare.Read))
    {
        page = ImGearFileFormats.LoadPage(fileStream, 0);
    }

    // Save a CAD file to a PNG image
    ImGearSavingFormats formatOut = ImGearSavingFormats.PNG;
    using (FileStream fileStream = new FileStream(outPath, FileMode.Create, FileAccess.Write, FileShare.Read))
    {
        ImGearFileFormats.SavePage(page, fileStream, formatOut);
    }
}
VB.NET
Copy Code
Imports System.IO
Imports ImageGear.Formats
Imports ImageGear.Formats.CAD

Public Sub CadToImage(inPath As String, outPath As String) 
    Dim page as ImGearCADPage

    ' Load file.
    Using fileStream as FileStream = New FileStream(inPath, FileMode.Open, FileAccess.Read, FileShare.Read))
        page = ImGearFileFormats.LoadPage(fileStream, 0)
    End Using

    ' Save a CAD file to a PNG image
    Dim formatOut As ImGearSavingFormats = ImGearSavingFormats.PNG
    Using fileStream as FileStream = New FileStream(outPath, FileMode.Create, FileAccess.Write, FileShare.Read))
        ImGearFileFormats.SavePage(page, fileStream, formatOut)
    End Using
End Sub
Any conversions made to the CADPage’s camera will reflect in the saved image.