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

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

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

    Vincent.Chan‘s Blog

    常用鏈接

    統(tǒng)計(jì)

    積分與排名

    網(wǎng)站

    最新評(píng)論

    如何把a(bǔ)wt或者swing的UI生成一個(gè)圖形文件

    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 閱讀(338) 評(píng)論(0)  編輯  收藏 所屬分類: Java

    主站蜘蛛池模板: 亚洲精品无码成人片在线观看 | 一个人看的免费观看日本视频www 一个人看的免费视频www在线高清动漫 | 日日AV拍夜夜添久久免费| 三年片在线观看免费观看大全中国| 亚洲亚洲人成综合网络| 免费精品国偷自产在线在线| 狠狠入ady亚洲精品| 亚洲AV永久无码精品水牛影视| 99re热免费精品视频观看 | 免费A级毛片无码A∨中文字幕下载| 亚洲色大成WWW亚洲女子| a级亚洲片精品久久久久久久| 亚洲人成免费电影| 免费无码国产V片在线观看| 久久久国产精品亚洲一区| 国产精品高清全国免费观看| 免费无遮挡无码永久视频| 无遮挡a级毛片免费看| 亚洲国产精品美女| 亚洲综合色婷婷七月丁香| 最近中文字幕免费mv视频8| 日本在线看片免费| 美女无遮挡免费视频网站| 亚洲人成网站在线观看播放动漫 | 亚洲小说区图片区另类春色| 日韩电影免费在线| 亚洲视频在线免费观看| 一级中文字幕免费乱码专区 | 香港经典a毛片免费观看看| 亚洲日产2021三区在线| 亚洲一区二区三区在线观看精品中文 | a毛看片免费观看视频| 美女扒开屁股让男人桶爽免费| 亚洲一区二区三区免费视频| 亚洲va在线va天堂va不卡下载 | 噜噜综合亚洲AV中文无码| 亚洲妓女综合网99| 久久亚洲精品成人无码网站| 91麻豆精品国产自产在线观看亚洲| 四虎永久成人免费影院域名| 在线观看无码AV网站永久免费|