我是一棵無人需要的小草

          java 拼接文字和圖片

          public static void test2() {
            try {
             // 讀取第一張圖片
             // File fileOne = new File("D:\\qq.jpg");
             // BufferedImage ImageOne = ImageIO.read(fileOne);
             // int width = ImageOne.getWidth();//圖片寬度
             // int height = ImageOne.getHeight();//圖片高度

             // 對第二張圖片做相同的處理
             File fileTwo = new File("D:\\qq.jpg");
             BufferedImage ImageTwo = ImageIO.read(fileTwo);

             int width = ImageTwo.getWidth();// 圖片寬度
             int height = ImageTwo.getHeight();// 圖片高度
             int height2 = 20;

             BufferedImage ImageOne = new BufferedImage(width, height2,
               BufferedImage.TYPE_4BYTE_ABGR);
             // ImageOne.get

             Graphics g = ImageOne.getGraphics();//   
             g.fillRect(0, 0, width, height);
             g.setColor(Color.blue);
             Font mFont = new Font("宋體", Font.PLAIN, 12);
             g.setFont(mFont);
             String text = "添加文字測試";
             g.drawString(text, 0, 10);
             // 從圖片中讀取RGB
             int[] ImageArrayOne = new int[width * height2];
             ImageArrayOne = ImageOne.getRGB(0, 0, width, height2,
               ImageArrayOne, 0, width);

             int[] ImageArrayTwo = new int[width * height];
             ImageArrayTwo = ImageTwo.getRGB(0, 0, width, height, ImageArrayTwo,
               0, width);

             // 生成新圖片
             BufferedImage ImageNew = new BufferedImage(width, height + height2,
               BufferedImage.TYPE_INT_RGB);
             ImageNew.setRGB(0, 0, width, height2, ImageArrayOne, 0, width);// 設置上半部分的RGB
             // ImageNew.setRGB(width,0,width,height,ImageArrayTwo,0,width);//設置右半部分的RGB
             ImageNew.setRGB(0, height2, width, height, ImageArrayTwo, 0, width);// 設置下半部分的RGB

             File outFile = new File("d:\\qq2.jpg");
             ImageIO.write(ImageNew, "jpg", outFile);// 寫圖片
            } catch (Exception e) {
             e.printStackTrace();
            }
           }

          posted on 2009-10-14 10:11 風舞亂亂 閱讀(2707) 評論(0)  編輯  收藏

          <2009年10月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導航

          公告

          我是一棵無人需要的小草

          隨筆分類(6)

          隨筆檔案(11)

          文章檔案(4)

          相冊

          風舞亂亂

          最新隨筆

          最新評論

          閱讀排行榜

          評論排行榜

          我是一棵無人需要的小草
          主站蜘蛛池模板: 株洲市| 中江县| 阳山县| 西城区| 绍兴市| 靖远县| 遂宁市| 乐陵市| 淮安市| 灵璧县| 宜兰县| 和平区| 石林| 许昌市| 潜江市| 上虞市| 平度市| 磴口县| 大足县| 福清市| 东辽县| 温泉县| 河西区| 旬阳县| 新丰县| 沛县| 大竹县| 邳州市| 万山特区| 邻水| 白银市| 集安市| 永福县| 伊宁市| 鄂尔多斯市| 垫江县| 商南县| 班戈县| 玛曲县| 宁强县| 寻甸|