我的代码是:
public class PngtoGIfTest {
// 转化成gif
public static void pngtoGif(String fromurl,String tourl){
try{
BufferedImage buffer = ImageIO.read(new File(fromurl));
        ImageIO.write(buffer,"gif",new FileOutputStream(tourl));
}catch(Exception e) {
e.printStackTrace();
}
}
public static boolean writeImage(RenderedImage im, String formatName,
String fileName) {
boolean result = false;
try {
result = ImageIO.write(im, formatName, new File(fileName));
} catch (IOException ioe) {
ioe.printStackTrace();
}
return result;
}
public static void main(String[] args) {
PngtoGIfTest.pngtoGif("D:\\14_2305_10034_0_0.png", "c:\\a.gif");
//生成的gif图片无法预览
}
}我的jdk是1.5的,不知道为什么,我们公司的就可以,在家就不行!实在不知道为什么!
希望大家帮忙啊!

解决方案 »

  1.   

    程序没问题的,以前家里电脑是正常的,系统是window xp,我就重做了一次系统,结果就这样了!
    不过现在这个代码是可以转的
    File file = new File(tourl);
    Image image = ImageIO
    .read(new File(fromurl));
    GIFEncoder encoder = new GIFEncoder(image);
    FileOutputStream output = new FileOutputStream(file);
    encoder.Write(output);

    output.close();
    但是得到的gif图片,用ultraedit打开,发现字节会多出几个0!
    一般gif图片的字节是“;”结尾多
      

  2.   

    谢谢大家的提醒,是jdk版本问题,换乘jdk1.6可以转gif,也不会出现字节多0的问题