<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    在路上

    路上有驚慌,路上有理想

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      28 Posts :: 1 Stories :: 10 Comments :: 0 Trackbacks
    1.linux安裝字體
       以微軟雅黑為例,找到msyh.ttf ,copy至下面的文件夾
       usr/share/fonts/msyh
      執行命令:fc-cache -fv
      重啟jvm即可
    2.drawString 部分代碼
    private static BufferedImage drawString(int type, boolean isWhite,
                int width, int height, String price, Font font_money, Font font,
                Graphics2D g2d, Rectangle2D bounds, Rectangle2D bounds_money) {
             BufferedImage image;
             //透明背景
              image = g2d.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT);  
             g2d.dispose();  
             g2d = image.createGraphics();  
             //反鋸齒字體
             g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
             if(!isWhite){
                 //非白字
                 g2d.setColor(new Color(236,0,137));  
             }else{
                 //白字
                 g2d.setColor(new Color(255,255,255));  
             }
             //字體居中
             double y = (height - bounds.getHeight()) / 2;      
             double ascent = -bounds.getY();      
             double baseY = y + ascent;      

             g2d.setStroke(new BasicStroke(1));  
             g2d.setFont(font_money);
             g2d.drawString(FONT_RMB_CHAR, -2, (int)baseY);  
             g2d.setFont(font);
             g2d.drawString(price, (int)bounds_money.getWidth()-4, (int)baseY);
             g2d.dispose();
             return image;
        }
    3.如果需要根據字符串的長度生成圖片的寬度,可以使用如下方法
     Rectangle2D bounds = font.getStringBounds(price, context);
     width = (int)(bounds.getWidth();

    4.批量生成,使用java自帶的線程池,并使用CompletionService,目的是在線程處理結束后得到生成成功的ProductId
          public boolean generateImagesBatch(){
              boolean flag=true;
              ExecutorService exec = Executors.newFixedThreadPool(8);
               CompletionService<CallBack> completionService=
                        new ExecutorCompletionService<CallBack>(exec);
              long startTime=System.currentTimeMillis();
                  String sql="select productId,price from prod";
                List<Map> skuList = this.cmsJdbcTemplate.queryForList(sql);
                for(Map map:skuList){
                    String prodId=((BigDecimal)map.get("productId")).toString();
                    double price=((BigDecimal)map.get("price")).doubleValue();
                    completionService.submit(new CreateImageConcurrent(prodId,price,FontEnum.ONE,false));               
                    completionService.submit(new CreateImageConcurrent(prodId,price,FontEnum.TWO,false));            }
                long endTime=System.currentTimeMillis()-startTime;
                log.info("query db time>>>>>>>>>>>>>>"+endTime/1000);
                
                Future<CallBack> future;
                int count=skuList.size()*6;
                log.info("generateImagesBatch count:"+count);
                try {
                    while(count>0){
                        future = completionService.take();
                        CallBack callBack = future.get();
                        if(null!=callBack){
                            count--; log.info("generateImagesBatch prod id:"+callBack.getSuccesMessage());                    }
                    }
                endTime=System.currentTimeMillis()-startTime;
                log.info("create images time>>>>>>>>>>>>>>"+endTime/1000);
                log.info("generateImagesBatch success!");
                flag=true;
                } catch (ExecutionException e) {
                    flag=false;
                    log.error("generateImagesBatch fail::ExecutionException::"+e.getMessage());
                } catch (InterruptedException e) {
                    flag=false;
                    log.error("generateImagesBatch fail::InterruptedException::"+e.getMessage());
                }finally{
                    exec.shutdown();
                }
                return flag;
          }
    posted on 2012-04-18 11:35 阮步兵 閱讀(1867) 評論(0)  編輯  收藏 所屬分類: Java
    主站蜘蛛池模板: 国产92成人精品视频免费| 国产成人免费一区二区三区| 国产成人99久久亚洲综合精品| 亚洲中文字幕无码永久在线| 免费一区二区无码视频在线播放 | 爽爽爽爽爽爽爽成人免费观看| 亚洲视频免费在线播放| 亚洲av永久无码精品漫画| 在线91精品亚洲网站精品成人| 免费观看男人免费桶女人视频| 亚洲尹人香蕉网在线视颅| 蜜桃成人无码区免费视频网站| 亚洲av手机在线观看| 亚洲免费人成视频观看| 永久免费的网站在线观看| 亚洲6080yy久久无码产自国产| 免费一级一片一毛片| a毛片在线看片免费| 亚洲综合视频在线观看| 一级特黄录像免费播放肥| 久久久久亚洲精品美女| 黄在线观看www免费看| 亚洲人成网站色7799| 免费观看AV片在线播放| 噜噜综合亚洲AV中文无码| 中文字幕第13亚洲另类| 无码AV片在线观看免费| 最新国产精品亚洲| 狠狠亚洲狠狠欧洲2019| 精品国产sm捆绑最大网免费站 | 四虎一区二区成人免费影院网址| 无码日韩人妻av一区免费| 国产亚洲精品2021自在线| 黑人精品videos亚洲人| 麻豆一区二区免费播放网站 | 国产AV日韩A∨亚洲AV电影 | 亚洲一卡2卡三卡4卡无卡下载 | 亚洲天堂电影在线观看| 免费观看四虎精品国产永久| 午夜不卡久久精品无码免费| 亚洲gay片在线gv网站|