import java.applet.*;
import java.awt.*;
import java.net.URL;public class MyImage extends Applet{ private static final long serialVersionUID = 1L; Image pic;
int h,w;
public void init(){
pic = getImage(getCodeBase(),"123.gif");
h = pic.getHeight(this);
w = pic.getWidth(this);
}
public void paint(Graphics g){
int x0 = 10,y0 = 120;
g.drawImage(pic,x0,y0,w,h*50,this); //注意此行中的第五个参数h*50, 但是却能画出来一个倒着的图
g.drawImage(pic,x0,y0+50,this); }
}解释见上面的注释
为啥高度设为这样的之后,图就会倒过来?
import java.awt.*;
import java.net.URL;public class MyImage extends Applet{ private static final long serialVersionUID = 1L; Image pic;
int h,w;
public void init(){
pic = getImage(getCodeBase(),"123.gif");
h = pic.getHeight(this);
w = pic.getWidth(this);
}
public void paint(Graphics g){
int x0 = 10,y0 = 120;
g.drawImage(pic,x0,y0,w,h*50,this); //注意此行中的第五个参数h*50, 但是却能画出来一个倒着的图
g.drawImage(pic,x0,y0+50,this); }
}解释见上面的注释
为啥高度设为这样的之后,图就会倒过来?
你换个新点的操作系统(不知道微软改了没有)或者改Linux应该不会这样
你把html文件也贴出来
// 看看h、w是什么值,我怀疑为负值。
System.out.println(h + "\t" + w);g.drawImage(pic,x0,y0,w,h*50,this);
还有,你让我测试的h,w,好像都是-1啊这是怎么回事~~~~~~~~~~~~~~~
public abstract int getHeight(ImageObserver observer)
Determines the height of the image. If the height is not yet known, this method returns -1 and the specified ImageObserver object is notified later. Parameters:
observer - an object waiting for the image to be loaded.
Returns:
the height of this image, or -1 if the height is not yet known.
See Also:
getWidth(java.awt.image.ImageObserver), ImageObserver
如果图象没有加载成功的话。h,w会返回-1,至于为什么出现图象倒,我觉得奇怪。因为h*50只是把图象扩大了而已。。并不会影响图象的角度。