Hi, Support:
Why the CAD.dll(Net v23.4 ) fail to export layer as jpg file?
The filesize of most of the exported jpgs is zero, whereas some are great than zero, but cannot be opened by image-viewer.
Dim Image As CadImage = TryCast(Aspose.CAD.Image.Load(InputCADFile), CadImage)
Dim rasterizationOptions As CadRasterizationOptions = New CadRasterizationOptions()
rasterizationOptions.PageWidth = W
rasterizationOptions.PageHeight = H
Dim TiffOptions As TiffOptions = New TiffOptions(TiffExpectedFormat.Default)
TiffOptions.VectorRasterizationOptions = rasterizationOptions
TiffOptions.Compression = Tiff.Enums.TiffCompressions.Lzw
TiffOptions.ResolutionSettings = New Aspose.CAD.ResolutionSetting(DPI, DPI)
Image.Save(OutPath, TiffOptions)
@ducaisoft
It seems you are experiencing issues with exporting layers from a CAD file to JPG format using Aspose.CAD. The problem of getting zero-byte files or files that cannot be opened may stem from a few common issues in the export process.
Here are some steps and code examples to help you troubleshoot and correctly export CAD layers to JPG:
-
Ensure Correct Layer Names: Make sure that the layer names you are trying to export actually exist in the CAD file. You can retrieve the list of layers from the CAD image and verify their names.
-
Use Proper Rasterization Options: When exporting, ensure that you are setting the rasterization options correctly. This includes specifying the page width and height, as well as the layers you want to export.
-
Exporting Layers: Here’s a sample code snippet that demonstrates how to export a specific layer to JPG format:
Dim image As CadImage = TryCast(Aspose.CAD.Image.Load(InputCADFile), CadImage)
Dim rasterizationOptions As New CadRasterizationOptions()
rasterizationOptions.PageWidth = 500 ' Set your desired width
rasterizationOptions.PageHeight = 500 ' Set your desired height
rasterizationOptions.Layers = New String() { "YourLayerName" } ' Specify the layer name
Dim jpegOptions As New JpegOptions()
jpegOptions.VectorRasterizationOptions = rasterizationOptions
' Save the image to JPG format
image.Save(OutPath, jpegOptions)
-
Check File Paths: Ensure that the output path (OutPath
) is valid and that you have write permissions to that location.
-
Debugging: If the output files are still not valid, consider checking the console for any error messages or exceptions that might provide more insight into what is going wrong.
By following these steps and using the provided code, you should be able to successfully export layers from your CAD file to JPG format. If you continue to face issues, please provide additional details about the specific layer names and any error messages you encounter.
@ducaisoft,
Could you please share the test file and the exact code, so we can reproduce and observe the same result as you.
Please refer to the dwg file attachment.
test.zip (507.9 KB)
@ducaisoft,
Thank you, we can confirm the issue with export to raster for the 23.4. This problem seems to be fixed for 24.1 (both for TIFF and JPG) and is not reproducible for the latest version 25.3 too. Please consider to use more recent versions.