2026-05.zip (293.7 KB)
您好,参考我想对cad文档进行截图,但是显示找不到setCenterPoint和setWidth、.setHeight方法;附件是示例代码,麻烦帮忙看一下
2026-05.zip (293.7 KB)
您好,参考我想对cad文档进行截图,但是显示找不到setCenterPoint和setWidth、.setHeight方法;附件是示例代码,麻烦帮忙看一下
@zou_yw,
您好。
我们的 API 并未包含所有这些方法。以下示例展示了如何导出文件的一部分。
CadImage cadImage = (CadImage) Image.load(input);
// size of crop rectangle
int width = 2;
int height = 2;
// start point of rectangle
Point topLeft = new Point(29, 11);
CadVportTableObject newView = new CadVportTableObject();
// note: exactly such table name is required for active view
newView.setName("*Active");
newView.setCenterPoint(new Cad2DPoint(topLeft.getX() + width / 2f, topLeft.getY() - height / 2f));
newView.setViewHeight(height);
newView.setViewAspectRatio(width / height);
// search for active viewport and replace it
for (int i = 0; i < cadImage.getViewPorts().size(); i++)
{
CadVportTableObject currentView = (CadVportTableObject)(cadImage.getViewPorts().get_Item(i));
if ((currentView.getName() == null && cadImage.getViewPorts().size() == 1) ||
currentView.getName().toLowerCase().equals("*active"))
{
cadImage.getViewPorts().set_Item(i, newView);
break;
}
}
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setNoScaling(true);
rasterizationOptions.setPageWidth(width*100);
rasterizationOptions.setPageHeight(height*100);
rasterizationOptions.setLayouts(new String[] { "Model" });
SvgOptions svgOptions = new SvgOptions();
svgOptions.setVectorRasterizationOptions(rasterizationOptions);
svgOptions.setTextAsShapes(true);
cadImage.save(pngName, svgOptions);
b5401314f39514e02331a1c3fdae69d3.png (267.5 KB)
您好,我尝试了您的代码。输出的图像为空白,
调整 width 、height 的范围依然显示空白
int width =2000;
int height = 2000;