Dynamics AX 中的图片处理

1、从本地读取图片文件,并判断格式是否附合要求。

 1 FilenameFilter filter = ['Image Files','*.bmp;*.jpg;*.gif;*.jpeg'];
 2 BinData binData = new BinData();
 3 str extention, path, nameOfFile;
 4 Container imageContainer ;
 5 imageFilePathName = WinAPI::getOpenFileName(element.hWnd(),filter,'', "@SYS53008", '','');
 6 if (imageFilePathname && WinAPI::fileExists(imageFilePathName))
 7 {
 8     [path, nameOfFile, extention] = fileNameSplit(imageFilePathName);
 9     if (extention == '.jpg')
10     {
11         binData.loadFile(imageFilePathName);
12         imageContainer = binData.getData();
13     }
14     else
15     {
16         throw error("@SYS89176");
17     }
18 }

2、将AX中的图片保存到本地文件夹。

 1 str path;
 2 FilenameFilter filter = ['Image Files','*.jpg'];
 3 CompanyImage companyImage;
 4 Image image;
 5 DialogBox dialogBox;
 6 ;
 7    
 8 path = WinAPI::getSaveFileName(0,filter,'','','','filename',0);
 9 if (path)
10 {
11   image = new Image();
12   image.setData(companyImage.Image);
13   if (WinAPI::fileExists(path))
14   {
15     dialogBox = new DialogBox(DialogBoxType::YesNoBox,strfmt("@HPH243",path),'','',DialogButton::Yes);
16        if (DialogButton::Yes == dialogBox.retval())
17          image.saveImage(path);
18   }
19   else
20   {
21     image.saveImage(path);
22   }
23 }

3、图片缩放显示在控件上。

1 image = new Image();
2 image.setData(imageContainer);
3  
4 w = image.width() * sel / 100;  //sel为缩放百分比
5 h = image.height() * sel / 100;
6  
7 image.resize(w, h, InterpolationMode::InterpolationModeDefault);
8  
9 Photo.image(image); //Photo为bitmap控件

4、图片的剪切,显示图片的控件窗口不能被其他窗口遮挡。

1 Container rect;
2 rect = WINAPI::getWindowRect(this.hWnd());//获取图片控件的屏幕坐标
3 int left,top;
4 left = conpeek(rect,1);
5 top = conpeek(rect,2);
6 image = new Image();
7 image.captureScreen(left,top,width,height);//根据坐标和大小进行剪切,该方法同样可以用来进行屏幕截图

5、导出图片到指定文件夹,适用于批量图片导出。

 1 str path;
 2 Image image;
 3 str filename = "test.jpg";
 4 image = new Image();
 5 image.setData(imageContainer );
 6 path = WinAPI::browseForPath(element.hWnd(),'');
 7 if (substr(path, strlen(path)-1,1) != "\\")
 8   path += "\\"; //如果选择的桌面,则要加上\
 9 path += filename;
10 image.saveImage(path);
原文地址:https://www.cnblogs.com/Jinnchu/p/2658690.html