posts - 38,  comments - 22,  trackbacks - 0

          /**
          ???? * 將某個組件上的圖形或組件另存為文件
          ???? * @param comp
          ???? * @param filename
          ???? * @return
          ???? */
          ??? public static boolean saveToJPEG(Component comp) {
          ??????? boolean result = true;
          ??????? try {
          ??????????? int w = comp.getWidth();
          ??????????? int h = comp.getHeight();
          ??????????? BufferedImage
          ??????????????? image = (BufferedImage) comp.createImage(w, h);
          ??????????? Graphics2D g2 = image.createGraphics();
          ??????????? comp.print(g2);

          ??????????? String filename = LocalAccess.getSaveFileName(comp,"JavaComponent.jpg");
          ??????????? if(filename==null)return false;
          ??????????? BufferedOutputStream bos =
          ??????????????? new BufferedOutputStream(new FileOutputStream(filename));
          ??????????? com.sun.image.codec.jpeg.JPEGImageEncoder encoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder(bos);
          ??????????? com.sun.image.codec.jpeg.JPEGEncodeParam jep = encoder.getDefaultJPEGEncodeParam(image);
          ??????????? jep.setQuality(1.0f, false);
          ??????????? encoder.setJPEGEncodeParam(jep);
          ??????????? encoder.encode(image);
          ??????????? bos.close();
          ??????? }
          ??????? catch (Exception e) {
          ??????????? result = false;
          ??????????? e.printStackTrace();
          ??????? }
          ??????? return result;
          ??? }

          posted on 2007-01-15 13:51 aaabbb 閱讀(269) 評論(0)  編輯  收藏 所屬分類: Swing
          主站蜘蛛池模板: 晋江市| 赣榆县| 汝州市| 岑巩县| 丽江市| 汝阳县| 红河县| 肇源县| 绥宁县| 田阳县| 五华县| 冕宁县| 年辖:市辖区| 武隆县| 临高县| 京山县| 余江县| 高安市| 怀宁县| 乌兰浩特市| 库车县| 阳春市| 濉溪县| 西和县| 平果县| 武夷山市| 南投县| 卫辉市| 长武县| 五寨县| 东安县| 桐梓县| 汽车| 中阳县| 洞头县| 泰和县| 保康县| 岳阳市| 衡东县| 利津县| 鹤峰县|