在NX1934中,有直接导出png图像的功能,采用二次开发,如下所示:
public static void ExportImage(string imageFile, NXOpen.Gateway.ImageExportBuilder.FileFormats fileFormats , NXOpen.Gateway.ImageExportBuilder.BackgroundOptions backgroundOption)
{
NXOpen.Session theSession = NXOpen.Session.GetSession();
NXOpen.Part workPart = theSession.Parts.Work;
NXOpen.Part displayPart = theSession.Parts.Display;
NXOpen.Session.UndoMarkId markId1;
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "起点");
NXOpen.UI theUI = NXOpen.UI.GetUI();
NXOpen.Gateway.ImageExportBuilder imageExportBuilder1;
imageExportBuilder1 = theUI.CreateImageExportBuilder();
imageExportBuilder1.RegionMode = false;
int[] regiontopleftpoint1 = new int[2];
regiontopleftpoint1[0] = 0;
regiontopleftpoint1[1] = 0;
imageExportBuilder1.SetRegionTopLeftPoint(regiontopleftpoint1);
imageExportBuilder1.RegionWidth = 1;
imageExportBuilder1.RegionHeight = 1;
imageExportBuilder1.FileFormat = fileFormats;
imageExportBuilder1.FileName =imageFile;
imageExportBuilder1.BackgroundOption = backgroundOption;
imageExportBuilder1.EnhanceEdges = false;
NXOpen.NXObject nXObject1;
nXObject1 = imageExportBuilder1.Commit();
theSession.DeleteUndoMark(markId1, "导出图像");
imageExportBuilder1.Destroy();
}
其中,NXOpen.Gateway.ImageExportBuilder.FileFormats是导出的文件格式,如.png等;NXOpen.Gateway.ImageExportBuilder.BackgroundOptions 是导出时背景颜色。
也可以用ufDisp.CreateImage("E:\\12.bng",UFDisp.ImageFormat.Png,UFDisp.BackgroundColor.White),创建png格式的图像文件。