<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Vincent.Chan‘s Blog

    常用鏈接

    統計

    積分與排名

    網站

    最新評論

    如何把awt或者swing的UI生成一個圖形文件

    package demo;

    import java.io.File;
    import org.jfree.chart.JFreeChart;
    import java.io.IOException;
    import java.io.OutputStream;
    import java.io.BufferedOutputStream;
    import java.io.FileOutputStream;
    import java.awt.image.BufferedImage;
    import org.jfree.chart.encoders.ImageFormat;
    import java.awt.Graphics2D;
    import java.awt.*;
    import java.awt.*;
    import org.jfree.chart.encoders.ImageEncoder;
    import org.jfree.chart.encoders.ImageEncoderFactory;
    import javax.swing.JFrame;
    import javax.imageio.ImageIO;

    public class ToImg {
      
    public ToImg() {
      }



      
    /**
       * Saves a chart to a file in JPEG format.
       *
       * 
    @param file  the file (<code>null</code> not permitted).
       * 
    @param quality  the JPEG quality setting.
       * 
    @param chart  the chart (<code>null</code> not permitted).
       * 
    @param width  the image width.
       * 
    @param height  the image height.
       *
       * 
    @throws IOException if there are any I/O errors.
       
    */

      
    public static void saveChartAsJPEG(File file,
                                         
    float quality,
                                         JFreeChart chart,
                                         
    int width,
                                         
    int height) throws IOException {

        
    if (file == null{
            
    throw new IllegalArgumentException("Null 'file' argument.");
        }

        
    if (chart == null{
            
    throw new IllegalArgumentException("Null 'chart' argument.");
        }

        OutputStream out 
    = new BufferedOutputStream(new FileOutputStream(file));

        BufferedImage images 
    = chart.createBufferedImage(width, height, null);
        BufferedImage image 
    = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 
    = image.createGraphics();
    //    draw(g2, new Rectangle2D.Double(0, 0, width, height), null, info);
        g2.dispose();

        writeBufferedImage(image, ImageFormat.JPEG, out, quality);
        out.close();
      }


      
    public static void writeBufferedImage(BufferedImage image, String format,
          OutputStream outputStream, 
    float quality)
          
    throws IOException {
        ImageEncoder imageEncoder
            
    = ImageEncoderFactory.newInstance(format, quality);
        imageEncoder.encode(image, outputStream);

      }


      
    public static void main(String[] args) {
        Robot robot 
    = null;
        
    try {
          
          JFrame f 
    = new Frame1(); 
          f.setSize(
    500,600);
          f.setVisible(
    true);
          f.setDefaultCloseOperation(
    2);
          BufferedImage image 
    = new BufferedImage(500600, BufferedImage.TYPE_INT_RGB);
          f.getContentPane().paint(image.getGraphics());
          FileOutputStream out 
    = new FileOutputStream("d:\\b.jpg");
          ImageIO.write(image, 
    "jpeg" , out);
          out.close();

    /**    
         抓圖  
          Robot robot = new java.awt.Robot();
          BufferedImage image = robot.createScreenCapture(new Rectangle(100, 100));
          ImageEncoder imageEncoder
              = ImageEncoderFactory.newInstance(ImageFormat.JPEG, 100);
          FileOutputStream out = new FileOutputStream("d:\\a.jpg");
          imageEncoder.encode(taget, out);
     }
    */


       }

        
    catch (Exception ex) {
          ex.printStackTrace();
        }


      }


    }

    posted on 2006-02-13 21:38 Vincent.Chen 閱讀(341) 評論(0)  編輯  收藏 所屬分類: Java

    主站蜘蛛池模板: 99精品视频免费观看| 久草免费在线观看视频| 青草草色A免费观看在线| 亚洲永久永久永久永久永久精品| 亚洲AV日韩AV永久无码免下载| 亚洲免费在线视频播放| 亚洲成a人无码亚洲成av无码| 国产男女猛烈无遮挡免费网站| 亚洲成a∨人片在无码2023| a级毛片100部免费观看| 久久亚洲私人国产精品| 久久亚洲精品无码av| 免费人妻无码不卡中文字幕18禁| 国产免费久久精品99久久| 婷婷亚洲综合五月天小说| 男人的好免费观看在线视频| 在线亚洲v日韩v| 成人影片麻豆国产影片免费观看| 亚洲精品色午夜无码专区日韩| 欧洲一级毛片免费| 亚洲AV无码精品无码麻豆| 两个人www免费高清视频| 免费无码精品黄AV电影| 麻豆安全免费网址入口| 亚洲黄色免费电影| 国产亚洲美女精品久久久久| 好男人视频社区精品免费| 一级毛片免费在线观看网站| 激情综合亚洲色婷婷五月| 国产成人精品亚洲精品| 老子影院午夜伦不卡亚洲| 亚洲高清视频免费| ww在线观视频免费观看| 三年片免费观看大全国语| 亚洲精品9999久久久久无码| 亚洲熟妇av一区二区三区下载 | 日韩版码免费福利视频| 中国人免费观看高清在线观看二区| 亚洲综合色丁香婷婷六月图片| 亚洲精品二区国产综合野狼| 免费国产真实迷j在线观看|