Javascript 检索indesign exported.png的正确长度和宽度

Javascript 检索indesign exported.png的正确长度和宽度,javascript,png,export,adobe-indesign,extendscript,Javascript,Png,Export,Adobe Indesign,Extendscript,我正在尝试编写一个javascript应用程序,以在indesign(CS5)中输出所选图像/组的长度和宽度,并将所选内容保存到.png文件中。问题是,我使用选择的visibleBounds生成的长度和宽度与导出图像的长度和宽度略有不同。更具体地说,如果图像高度大于宽度,则生成的高度将与生成的.png高度相同,但生成的宽度将稍小。相反,如果宽度更大,生成的高度将稍小。以下是我一直使用的代码: dest = Folder.selectDialog('Save report'); selected

我正在尝试编写一个javascript应用程序,以在indesign(CS5)中输出所选图像/组的长度和宽度,并将所选内容保存到.png文件中。问题是,我使用选择的visibleBounds生成的长度和宽度与导出图像的长度和宽度略有不同。更具体地说,如果图像高度大于宽度,则生成的高度将与生成的.png高度相同,但生成的宽度将稍小。相反,如果宽度更大,生成的高度将稍小。以下是我一直使用的代码:

dest = Folder.selectDialog('Save report');
selected = app.activeDocument.selection[0];
filer = new File (dest+'/'+'testImage.png');
h = selected.visibleBounds[2] - selected.visibleBounds[0];
w = selected.visibleBounds[3] - selected.visibleBounds[1];
alert('height: '+h+'\nwidth: '+w);
selected.exportFile(ExportFormat.PNG_FORMAT, filer, false);

我还应该指出,这个问题只发生在相对较小的图像上。似乎图像越小,影响越大。任何帮助都将不胜感激。

我也发现了这个问题,即使完全相同的图像也会根据其在页面上的位置导出不同的大小。我想问题是inDesign在最低级别使用厘米或英寸,而不是像素

然而,我最终解决这个问题的方法是在导出图像后将其放置在inDesign文档上,并检查宽度和高度以确保两个值都正确此解决方案仅在以后知道图像大小时有效,一旦导出,在导出之前我没有找到知道图像大小的方法,因为有时图像大小会在没有任何明显原因的情况下更改:

selected.exportFile(ExportFormat.PNG_FORMAT, filer, false);
//These lines load the image into the document, check the size of the image file previously exported, and writes the correct measure into the XML file
var imageFile = File(filer);
var imageGraphic = app.activeDocument.pages.item(0).place(imageFile, null);
imageGraphicItem = imageGraphic[0];
var imageFrame = imageGraphicItem.parent;
var correctImageWidth = Math.round(imageFrame.visibleBounds[3]-imageFrame.visibleBounds[1]);
var correctImageHeight = Math.round(imageFrame.visibleBounds[2]-imageFrame.visibleBounds[0]);
//Do something
imageGraphicItem.parent.remove(); 

希望有帮助

尝试过使用geometricBounds而不是visibleBounds吗?是的,geometricBounds给了我完全相同的结果:/hm。也许可以尝试设置脚本使用的单位。app.activeDocument.viewPreferences.properties={horizontalMeasurementUnits:MeasurementUnits.mm,VerticalMeasureUnits=MeasurementUnits.mm}