2 zt1771 zt1771 于 2014.09.28 10:53 提问

图片为什么显示不出来

package gui.practice;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.JFrame;

public class Test {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    BufferedImageDemo1 window = new BufferedImageDemo1();
}

}

class BufferedImageDemo1 extends JFrame {
Image image;
BufferedImage bufImage;

public BufferedImageDemo1() {
    super();
    URL url;
    try {
        url = new URL("file:///D:/bird.jpg");
        image = Toolkit.getDefaultToolkit().getImage(url);
        int width, height;
        width = image.getWidth(this);
        height = image.getHeight(this);
        bufImage = new BufferedImage(
                width < 1 ? 500 : image.getWidth(this), height < 1 ? 500
                        : image.getHeight(this),
                BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = bufImage.createGraphics();
        g.drawImage(image, 0, 0, this);
        this.setSize(300, 300);
        setVisible(true);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!