《java与图像》

来源:互联网 发布:阴阳师自动刷御魂软件 编辑:程序博客网 时间:2024/06/05 12:01

                                                                                     Java与图像


1、java支持的图像类型:GIF,JPEG,BMP


2、Image类


首先申请一个Image对象
Image img =getImage(URL url,String name) url是图像地址,name是图片名称
通常使用:
Image img =getImage(getCodBase(),String name) getCodBase()获取当前小应用程序的URL,也就是在同一目录下
图像被加载后,就可以在paint()中绘制了
drawImage(Image img,int x,int y,ImageObserver observer)
img是上面获取的图像, x,y是指定图像左上角的位置,observer是加载图像时的图像观察器
Applet类已经实现了ImageObserver接口,所以可以直接使用this作为最后一个参数
drawImage(Image img,int x,int y,int width,int height,ImageObserver observer)
width和height是要绘制的图像的宽和高
可以使用img.getHeight(this)和img.getWidth(this)来获取被加载的图像的宽和高


3、设置Java窗口图标
Frame对象可以使用setIconImage(Image img)方法设置左上角图标,默认图标是咖啡杯

原创粉丝点击