我是一棵无人需要的小草

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 风舞乱乱 阅读(2694) 评论(0)  编辑  收藏

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

导航

公告

我是一棵无人需要的小草

随笔分类(6)

随笔档案(11)

文章档案(4)

相册

风舞乱乱

最新随笔

最新评论

阅读排行榜

评论排行榜

我是一棵无人需要的小草