public static boolean write(RenderedImage im,
                            String formatName,  //这个参数是什么意思,是文件名吗?
                            File output)  
                     throws IOException

解决方案 »

  1.   

    public static boolean write(RenderedImage im,
                                String formatName,
                                File output)
                         throws IOException使用支持给定格式的任意 ImageWriter 将一个图像写入 File。如果已经有一个 File 存在,则丢弃其内容。 参数:
    im - 要写入的 RenderedImage。
    formatName - 包含格式非正式名称的 String。
    output - 将在其中写入数据的 File。 
    返回:
    如果没有找到合适的 writer,则返回 false。 
    抛出: 
    IllegalArgumentException - 如果任何参数为 null。 
    IOException - 如果在写入过程中发生错误。
      

  2.   

    按照指定格式输出到文件的意思吧formatName可能是bmp,jpeg,png等
      

  3.   

    参考看看怎么用
    if (width > 0 || hight > 0) {    
                // 原图的大小    
                int sw = srcImage.getWidth();    
                int sh = srcImage.getHeight();    
                // 如果原图像的大小小于要缩放的图像大小,直接将要缩放的图像复制过去    
                if (sw > width && sh > hight) {    
                    srcImage = resize(srcImage, width, hight);    
                } else {    
                    String fileName = saveFile.getName();    
                    String formatName = fileName.substring(fileName    
                            .lastIndexOf('.') + 1);    
                    ImageIO.write(srcImage, formatName, saveFile);    
                    return;    
                }    
            }    
      

  4.   

    mport java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;import javax.imageio.ImageIO;
    public class Img
    {
    static BufferedImage  bufImg ;
    public static void main(String[] args) throws IOException
    {
    try
    {
      bufImg = ImageIO.read(new File("g:\\tt.jpg"));
    }catch(Exception e)
    {}
    int a = bufImg.getRGB(0, 0);
       System.out.println("a1="+a);
     a = bufImg.getRGB(0, 1);
       System.out.println("a2="+a);
     a = bufImg.getRGB(1, 0);
       System.out.println("a3="+a);
     a = bufImg.getRGB(1, 1);
       System.out.println("a4="+a);
       bufImg.setRGB(0,1,-1);
      ImageIO.write(bufImg, ".jpg", new File("g:\\tt.jpg"));
              //为什么这句话,写入文件时,文件总是无法成功写入,这是为什么??高手,救我。
    }
    }
      

  5.   

    if (width > 0 || hight > 0) {    
                // 原图的大小    
                int sw = srcImage.getWidth();    
                int sh = srcImage.getHeight();    
                // 如果原图像的大小小于要缩放的图像大小,直接将要缩放的图像复制过去    
                if (sw > width && sh > hight) {    
                    srcImage = resize(srcImage, width, hight);    
                } else {    
                    String fileName = saveFile.getName();    
                    String formatName = fileName.substring(fileName    
                            .lastIndexOf('.') + 1);    
                    ImageIO.write(srcImage, formatName, saveFile);    
                    return;    
                }    
            }    
      

  6.   

     ImageIO.write(bufImg, ".jpg", new File("g:\\tt.jpg"));为什么无法成功写入!!!
      

  7.   

    ImageIO.write(bufImg, ".JPEG", new File("g:\\tt.jpg")); 
    把jpg改成JPEG