java的image不支持jpg文件,所以getWidth()函数无作用,你把文件格式转换一下吧

解决方案 »

  1.   

    我把你的程序在我的机器上编译了一下,结果为:
    method getWidth(JpgGet) not found in class java.awt.Image at line 68,column 19
    method getHeight(JpgGet) not found in class java.awt.Image at line 69,column 20
    而且你的程序没有main()函数,你怎末运行?
      

  2.   

    Scale an Image
    import java.awt.image.*;
    import java.awt.*;
    import java.net.*;public class app extends java.applet.Applet {
      Image source;
      Image resizedImage;  public void init() {
        MediaTracker media = new MediaTracker(this);
        // java how-to image for example
        source = getImage(getDocumentBase(),"jht.gif");
        media.addImage(source,0);
        try {
          media.waitForID(0);
          // scale down, half the original size  
          ImageFilter replicate = 
             new ReplicateScaleFilter
               (source.getWidth(this)/2, source.getHeight(this)/2);
          ImageProducer prod = 
             new FilteredImageSource(source.getSource(),replicate);
          resizedImage = createImage(prod);
          media.addImage(resizedImage,1);
          media.waitForID(1);
          } 
        catch(InterruptedException e) {}
        }  public void paint(Graphics g) {
        g.drawImage(source, 10,10,this);
        g.drawImage(resizedImage,10, 80,this);
        }
    }
     
      

  3.   

    得到图像宽度和高度的方法:import javax.swing.*;...String str="g:\\test.jpg";
    ImageIcon ii=ImageIcon(str);
    int width=ii..getIconWidth();
    int height=ii.getIconHeight();