Dynamics AX 中的图片处理

 

 

 

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

 

 

 

    FilenameFilter filter = ['Image Files','*.bmp;*.jpg;*.gif;*.jpeg'];

    BinData binData = new BinData();

    str extention, path, nameOfFile;

    Container imageContainer ;

    imageFilePathName = WinAPI::getOpenFileName(element.hWnd(),filter,'', "@SYS53008", '','');

    if (imageFilePathname && WinAPI::fileExists(imageFilePathName))

    {

        [path, nameOfFile, extention] = fileNameSplit(imageFilePathName);

        if (extention == '.jpg')

        {

            binData.loadFile(imageFilePathName);

            imageContainer = binData.getData();

 

 

 

        }

        else

        {

            throw error("@SYS89176");

        }

    }

 

 

 

2.AX中的图片保存到本地文件夹

    str path;

    FilenameFilter filter = ['Image Files','*.jpg'];

    CompanyImage companyImage;

    Image image;

    DialogBox dialogBox;

 

 

 

    ;

   

   

        path = WinAPI::getSaveFileName(0,filter,'','','','filename',0);

        if(path)

        {

            image = new Image();

            image.setData(companyImage.Image);

             if(WinAPI::fileExists(path))

            {

                 dialogBox = new DialogBox(DialogBoxType::YesNoBox,strfmt("@HPH243",path),'','',DialogButton::Yes);

                 if(DialogButton::Yes == dialogBox.retval())

   image.saveImage(path);

     }

     else

  {

  image.saveImage(path);

  }

 }

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

  image = new Image();

  image.setData(imageContainer);

 

 

 

            w = image.width()*sel/100;

            h = image.height()*sel/100;

 

 

 

            image.resize(w,h,InterpolationMode::InterpolationModeDefault);

 

 

 

            Photo.image(image); //Photobitmap控件

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

 Container rect;

 rect = WINAPI::getWindowRect(this.hWnd());//获取图片控件的屏幕坐标

 int left,top;

 left = conpeek(rect,1);

 top = conpeek(rect,2);

 image = new Image();

        image.captureScreen(left,top,width,height);//根据坐标和大小进行剪切,该方法同样可以用来进行屏幕截图

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

 str path;

 Image image;

 str filename = "test.jpg";

 image = new Image();

 image.setData(imageContainer );

 path = WinAPI::browseForPath(element.hWnd(),'');

 if(substr(path ,strlen(path)-1,1)!="\\")

            path+="\\";//如果选择的桌面,则要加上\

 path += filename;

 image.saveImage(path);

 

附加: 获取用户选中的多条记录,以EmplTable为例:

 for(emp=EmplTable_ds.getFirst(1) EmplTable_ds.getFirst(1):EmplTable_ds.cursor();emp;emp=EmplTable_ds.getNext())

        {

            //do something

        }

posted on 2015-04-29 16:15  Kobe.Zhang  阅读(217)  评论(0编辑  收藏  举报

导航