评估 cad-java 25.6 转换 png/jpg 时会出现错误

试了其它的几版本也是有问题,
是我的 dwg 有问题? 还是 cad-java 的bug 呢?
详细Exception 参考:

class com.aspose.cad.cadexceptions.ImageSaveException: Image export failed. Value cannot be null.
Parameter name: s
 ---> class com.aspose.cad.internal.Exceptions.ArgumentNullException: Value cannot be null.
Parameter name: s
com.aspose.cad.internal.aC.m.c(Unknown Source)
com.aspose.cad.internal.fz.k.a(Unknown Source)
com.aspose.cad.internal.fz.p.a(Unknown Source)
com.aspose.cad.internal.fz.p.a(Unknown Source)
com.aspose.cad.internal.fs.d.a(Unknown Source)
com.aspose.cad.internal.fs.d.a(Unknown Source)
com.aspose.cad.internal.fs.d.a(Unknown Source)
com.aspose.cad.internal.fs.m.b(Unknown Source)
com.aspose.cad.internal.fo.k.a(Unknown Source)
com.aspose.cad.internal.fo.k.b(Unknown Source)
com.aspose.cad.internal.fo.k.c(Unknown Source)
com.aspose.cad.internal.fo.d.a(Unknown Source)
com.aspose.cad.internal.fo.d.a(Unknown Source)
com.aspose.cad.internal.fo.i.a(Unknown Source)
com.aspose.cad.t.a(Unknown Source)
com.aspose.cad.internal.b.f.invoke(Unknown Source)
com.aspose.cad.system.Threading.j.invoke(Unknown Source)
com.aspose.cad.system.Threading.n.run(Unknown Source)
java.base/java.lang.Thread.run(Thread.java:1583)
   --- End of inner exception stack trace ---
com.aspose.cad.Image.b(Unknown Source)
com.aspose.cad.Image.a(Unknown Source)
com.aspose.cad.s.a(Unknown Source)
com.aspose.cad.internal.eS.b.a(Unknown Source)
com.aspose.cad.internal.eS.c.a(Unknown Source)
com.aspose.cad.Image.save(Unknown Source)

@hcmsxy

Cause

The error you’re encountering, ImageSaveException: Image export failed. Value cannot be null., indicates that there is a problem with the parameters being passed during the conversion process. This is often due to missing or incorrect settings in your CAD file or the conversion options.

Solution

To resolve this issue, please follow these steps:

  1. Check the CAD File: Ensure that the DWG or DXF file is not corrupted and is compatible with the version of Aspose.CAD you are using.

  2. Set Page Dimensions: Make sure to set the PageWidth and PageHeight properties in the CadRasterizationOptions. These are mandatory for the conversion process.

  3. Use Correct Options: Ensure that you are using the appropriate ImageOptionsBase for the format you are trying to save (e.g., PNG, JPEG).

  4. Enable Error Tracking: Implement error tracking to obtain more detailed information about what might be going wrong during the conversion.

Code

Here’s a sample code snippet to guide you through the conversion process:

String srcFile = "path/to/your/file.dwg"; // Path to your DWG file
Image image = Image.load(srcFile);

// Create an instance of CadRasterizationOptions
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1200); // Set the desired width
rasterizationOptions.setPageHeight(1200); // Set the desired height

// Create an instance of ImageOptionsBase for PNG
ImageOptionsBase options = new PngOptions();
options.setVectorRasterizationOptions(rasterizationOptions);

// Save the image
image.save("path/to/output/image.png", options);

Next Steps

  1. Verify that the CAD file is valid and not corrupted.
  2. Ensure that you have set the PageWidth and PageHeight correctly.
  3. If the issue persists, test with a different CAD file to determine if the problem is specific to the original file.
  4. If you continue to encounter issues, please provide additional details about the CAD file and the specific settings you are using.

Please let me know if you need further assistance!

@hcmsxy,
您能否分享 DWG 文件和您使用的代码,以便我们可以直接重现该问题?