Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active December 23, 2021 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/d6486d0e1068b73b822ae8651c6759f2 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/d6486d0e1068b73b822ae8651c6759f2 to your computer and use it in GitHub Desktop.
Convert DWG/DXF CAD File to JPG, PNG, GIF Image Programmatically using Java
// Load input CAD file
Image image = Image.load("Test.dwg");
// Create an instance of CadRasterizationOptions
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
// Set page width & height
rasterizationOptions.setPageWidth(1200);
rasterizationOptions.setPageHeight(1200);
// Create an instance of GifOptions for the resultant image
ImageOptionsBase options = new GifOptions();
// Set rasterization options
options.setVectorRasterizationOptions(rasterizationOptions);
// Convert CAD DWG DXF file to GIFF image
image.save("output_image.giff" , options);
// Load input DWG file
Image image = Image.load("Test.dwg");
// Create an instance of CadRasterizationOptions
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
// Set page width & height
rasterizationOptions.setPageWidth(1200);
rasterizationOptions.setPageHeight(1200);
// Create an instance of JpegOptions for the resultant image
ImageOptionsBase options = new JpegOptions();
// Set rasterization options
options.setVectorRasterizationOptions(rasterizationOptions);
// Convert CAD DWG DXF file to JPG image
image.save("output_image.jpg" , options);
// Load input DWG file
Image image = Image.load("Test.dwg");
// Create an instance of CadRasterizationOptions
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
// Set page width & height
rasterizationOptions.setPageWidth(1200);
rasterizationOptions.setPageHeight(1200);
// Create an instance of PngOptions for the resultant image
ImageOptionsBase options = new PngOptions();
// Set rasterization options
options.setVectorRasterizationOptions(rasterizationOptions);
// Convert CAD DWG DXF file to PNG image
image.save("output_image.png" , options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment