用java在剪贴板中读取出了图片信息,保存为了Image类型,但是不知道该如何存储成图片文件,各位朋友帮帮忙啊

解决方案 »

  1.   

    public class JpgTest { public static void main(String[] args) throws Exception {
      File _file = new File("1.jpg"); //读入文件
      Image src = javax.imageio.ImageIO.read(_file); //构造Image对象
      int wideth = src.getWidth(null); //得到源图宽
      int height = src.getHeight(null); //得到源图长
      BufferedImage tag = new BufferedImage(wideth / 2, height / 2,
        BufferedImage.TYPE_INT_RGB);
      tag.getGraphics().drawImage(src, 0, 0, wideth / 2, height / 2, null); //绘制缩小后的图
      FileOutputStream out = new FileOutputStream("newfile.jpg"); //输出到文件流
      JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
      encoder.encode(tag); //近JPEG编码
      //System.out.print(width+"*"+height);                              
      out.close();
     }