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
          主站蜘蛛池模板: 农安县| 金山区| 红安县| 涿鹿县| 新建县| 湟中县| 肇东市| 景东| 闽清县| 桑植县| 江华| 博客| 乌鲁木齐市| 修水县| 闽清县| 浦城县| 仁化县| 汉寿县| 上饶县| 武鸣县| 霍邱县| 宜阳县| 宁安市| 静安区| 裕民县| 个旧市| 嵊泗县| 安康市| 临朐县| 大邑县| 吴桥县| 南平市| 勐海县| 英超| 浦城县| 潼南县| 儋州市| 新和县| 和政县| 祁门县| 新民市|