zoukankan      html  css  js  c++  java
  • 报表打印网络按比例打印网络图片

    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) { } }

      

  • 相关阅读:
    Android5.0之Activity的转场动画
    Android5.0之CardView的使用
    Android5.0之CoordinatorLayout的使用
    Android5.0之NavigationView的使用
    Android开发之Bitmap二次采样
    android自定义View之NotePad出鞘记
    android自定义View之仿通讯录侧边栏滑动,实现A-Z字母检索
    android自定义View之钟表诞生记
    Spring经典高频面试题,原来是长这个样子
    Redis: 缓存过期、缓存雪崩、缓存穿透、缓存击穿(热点)、缓存并发(热点)、多级缓存、布隆过滤器
  • 原文地址:https://www.cnblogs.com/sxypeace/p/4580641.html
Copyright © 2011-2022 走看看