posts - 3, comments - 0, trackbacks - 0, articles - 2
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

imageIO

Posted on 2007-08-09 10:11 求知 阅读(349) 评论(0)  编辑  收藏
                                 

import java.io.File;
import java.io.FileOutputStream;
import java.awt.Image;
import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

public class JpgTest {

 public static void main(String[] args) throws Exception {
  File _file = new File("Winter.jpg");
  File small_img = new File("no.gif");
  Image src = ImageIO.read(_file);
  Image embed = ImageIO.read(small_img);
  int wideth = src.getWidth(null);
  int height = src.getHeight(null);
  BufferedImage tag = new BufferedImage(wideth, height,
    BufferedImage.TYPE_INT_RGB);
  tag.getGraphics().drawImage(src, 0, 0, wideth, height, null);
  tag.getGraphics().drawImage(embed, 50, 50, null);
  FileOutputStream out = new FileOutputStream("newfile.jpg");
  JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
  encoder.encode(tag);
  out.close();
 }
}


只有注册用户登录后才能发表评论。


网站导航: