You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将带标注和比例尺的.dm3文件转换为.jpg/jpeg格式图像

问题原因

报错“the format cannot contain the data to be saved”的核心原因是ImageDocumentSaveToFile调用时会尝试将DM图像文档的原始数据、专属元数据、标注信息全部写入目标文件,而JPG格式仅支持存储普通栅格图像内容,无法兼容DM的专属文档结构,因此抛出错误。
软件界面的批量转换功能逻辑是先将带比例尺、标注的图像显示内容渲染为普通RGB彩色图像,再对渲染后的图像执行格式导出,因此可以正常导出。

修正后的脚本

你需要先捕获当前图像显示区域的渲染内容,再将渲染得到的RGB图像保存为JPG,修改后的代码如下:

image test:=IntegerImage("test",2,1,100,100)
test.ShowImage()
image frontimage:=GetFrontImage()
string  filename=getname(frontimage)
imagedisplay disp = frontImage.ImageGetImageDisplay(0)
disp.applydatabar()

// 新增:捕获当前显示区域的带标注渲染图像
image renderedImg = disp.ImageDisplayGetDisplayRGB()

string directoryname, pathname
number length
if(!SaveAsDialog("","Do Not Change Me",directoryname)) exit(0)
length=len(directoryname)-16 
directoryname=mid(directoryname,0,length) 
// 补充jpg后缀避免文件无后缀无法识别
pathname=directoryname+filename+".jpg"

// 直接保存渲染后的RGB图像,而非原始图像文档
renderedImg.SaveAs("JPG", pathname, 0)
注意事项
  • 渲染得到的RGB图像已经包含了所有显示在界面上的比例尺、标注、数据条内容,和界面导出的效果完全一致
  • 如果需要批量处理多文件,只需要在外侧加遍历dm3文件的循环,逐个打开文件执行上述渲染、保存逻辑即可

内容的提问来源于stack exchange,提问作者user11078158

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 15:24:04