我用
img = ImageIO.read(new File("res/123.gif"))的方法读取图片
但是网页上不能显示?
难道只能用img=getImage(getCodeBase(),“res/123.gif");的方法读取吗???
哪位好心的大哥能指点一下啊!!

解决方案 »

  1.   

    GIF 图像 writer 插件保证满足以下要求的图像能无损失地写入: 
    band 数是 1; 
    每个采样的位数不大于 8; 
    颜色分量的大小不大于 8。 --ImageIO.read -> gif图像有一些约束条件,你换个jpg等格式的图片试一下。
      

  2.   

    BufferedImage img = ImageIO.read(new File("res/123.gif"));OutputStream sos=response.getOutputStream(); JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(sos); encoder应该才是图像
      

  3.   

        import java.io.File;
      import java.io.FileOutputStream;
      import java.awt.Graphics;
      import java.awt.Image;
      import java.awt.image.BufferedImage;
      
      import com.sun.image.codec.jpeg.JPEGCodec;
      import com.sun.image.codec.jpeg.JPEGImageEncoder;
      
      public class JpgTest {
      
      public void JpgTset() throws Exception{
      File _file = new File("/Order005-0001.jpg"); //读入文件
      Image src = javax.imageio.ImageIO.read(_file); //构造Image对象
      int wideth=src.getWidth(null); //得到源图宽
      int height=src.getHeight(null); //得到源图长
      BufferedImage tag = new BufferedImage(wideth/2,height/2,BufferedImage.TYPE_INT_RGB);
      tag.getGraphics().drawImage(src,0,0,wideth/2,height/2,null); //绘制缩小后的图
      FileOutputStream out=new FileOutputStream("newfile.jpg"); //输出到文件流
      JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); 
      encoder.encode(tag); //近JPEG编码
      //System.out.print(width+"*"+height); 
      out.close();
      }
      }
      

  4.   

    ImageIcon imageIcon = new ImageIcon("1.gif");
    frame.setIconImage(imageIcon.getImage());