1, 读取图片
static container SML_ImgUrl2Bitmap(str imgUrl,str newfileName = 'axTmpImgName1111') { System.Net.HttpWebRequest httpRequest = null; System.Net.HttpWebResponse httpResponse = null; CLRObject clro = null; System.IO.Stream stream; System.IO.StreamReader reader; System.Drawing.Image webImage ; BinData bidData=new BinData(); Bitmap Bitmap; str saveFilePath; str filepath, filename, fileExt; real height,width; ; [filepath, filename, fileExt] = fileNameSplit(imgUrl); filePath= WinAPI::getTempPath(); filename= newfileName; new InteropPermission(InteropKind::ClrInterop).assert(); try { clro = System.Net.WebRequest::Create(imgUrl); httpRequest = clro; httpResponse = httpRequest.GetResponse(); stream = httpResponse.GetResponseStream(); reader = new System.IO.StreamReader(stream); webImage = System.Drawing.Image::FromStream(stream); saveFilePath = filePath+newfileName+fileExt; webImage.Save(saveFilePath); bidData.loadFile(saveFilePath); Bitmap = bidData.getData(); height = webImage.get_Height(); width = webImage.get_Width();
} catch (Exception::CLRError) { return [Bitmap,0,0]; } return [Bitmap,height,width]; }
2, 按比例显示图片,A4纸,纵向打印
void initProdImg() { InventParameters InventParameters;
str imgUrl; #define.PicMaxWidth(18) // 允许图片最大宽度 #define.PicMaxHeight(8) // 允许图片最大高度 container scaleSize( int currW, int currH){ real maxW = #PicMaxWidth,maxH=#PicMaxHeight; real ratio = currH / currW; if( currH<= 144) maxH = 3; else if( currH<= 192) maxH = 4; else if( currH<= 240) maxH = 5; else if( currH<= 288) maxH = 6; if(currW >= maxW){ currW = maxW; currH = currW * ratio; } if(currH >= maxH){ currH = maxH; currW = currH / ratio; } return [currW, currH]; } void resetH(int currH){ ctrItemImg.height( currH,Units::cm); } void resetW(int currW){ ctrItemImg.width( currW,Units::cm); } ; InventParameters = InventParameters::find(); imgUrl = InventParameters.SML_InventImgUrl + curProdTable.sml_InventTableExt().SML_InventImgUrl; try { [prodImg,imgHeight,imgWidth] = SML_ImgUrl2Bitmap( imgUrl); if( !imgHeight || !imgWidth) { resetH(0); return; } else { [imgWidth,imgHeight] = scaleSize( imgWidth,imgHeight); resetH (imgHeight); resetW (imgWidth); ctrItemImg.resizeBitmap( true);// 允许图片按控件尺寸缩放。 } } catch(Exception::CLRError) { } }