ImageIcon - javax.swing.*;
Image - java.awt.*;//Image 是表示图形图像的所有类的超类
在组件上画图,使用的是Graphics中的drawImage方法
1.需要有一个封装图像数据的Image对象:
Image img=new ImageIcon(String filename).getImage();
2.使用drawImage Graphics:
drawImage(Image img, int x, int y, ImageObserver observer) //绘制指定图像中当前可用的图像。最后一个参数可以用null
3.复制某块区域的图形到新位置
copyArea(int x, int y, int width, int height, int dx, int dy) //将组件的区域复制到由 dx 和 dy 指定的距离处。
public void paintComponent(Graphics g){
Graphics2D g2d=(Graphics2D)g;
Image img=new ImageIcon("F:\\图片\\MHP3\\logo\\mhp3rd_dl_l01\\mhp3rd_dl_l01.png").getImage();
g2d.drawImage(img,0,0,null);
g2d.copyArea(0, 0, img.getWidth(this), img.getHeight(this), 0, img.getHeight(null));
}