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); }
}解释见上面的注释
为啥高度设为这样的之后,图就会倒过来?

解决方案 »

  1.   

    我以前好像看到过什么Windows操作系统原点的问题,是会出现倒的影响。
    你换个新点的操作系统(不知道微软改了没有)或者改Linux应该不会这样
      

  2.   

    <Applet>标签中所设置的width和height是多少?
    你把html文件也贴出来
      

  3.   

    我没用html,我是直接在eclipse中运行的
      

  4.   


    // 看看h、w是什么值,我怀疑为负值。
    System.out.println(h + "\t" + w);g.drawImage(pic,x0,y0,w,h*50,this);
      

  5.   

    你能不能给我一个截图?[email protected]
      

  6.   

    to:UnAgain() 我截了一张图,想发给你,但是邮箱好像出了点问题,点附件后没有任何反应,也没办法发
    还有,你让我测试的h,w,好像都是-1啊这是怎么回事~~~~~~~~~~~~~~~
      

  7.   

    getHeight
    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只是把图象扩大了而已。。并不会影响图象的角度。