ImageIcon & Image - 在组件上打印图片
2015-06-11 20:04
232 查看
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));
}
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));
}
相关文章推荐
- codeforces 550A
- HDU1728---逃离迷宫
- ios第一天
- poj 1655 树形dp
- GIS空间分析 对栅格数据分析,距离分析,点位置查找
- Java知多少(89)列表和组合框
- 对JDBC的一些理解
- 黑马程序员——java基础——集合框架(一:单列集合(Collection体系))
- 线程同步:信号量
- x210v3开发板u-boot-2012.10移植之十---串口摇身一变控制台
- 已下是转载如有冒犯,请见谅
- mongodb.core.query.Criteria 查询非空(ne)和排序(sort)
- 局域网雨云蠕虫病毒的处理
- OOAD 学习笔记 九
- poj 1269 Intersecting Lines
- Laravel控制器调用model的两种方法
- hdu 4296 Buildings(贪婪)
- spring中常用的注解
- spring无法获取jar包中的xml配置
- [LeetCode]Max Points on a Line