JDK升级到1.7后 com.sun.image.codec.jpeg不存在

源:http://stackoverflow.com/questions/8015291/how-to-replace-com-sun-image-codec-jpeg-jpegimageencoder-in-this-code
评:

JDK升级到1.7后编译的时候会出现 com.sun.image.codec.jpeg jar不存在

需要修改程序代码将原来的

[java] view plaincopyprint?在CODE上查看代码片派生到我的代码片

    FileOutputStream out = new FileOutputStream(targetImg); 
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); 
    encoder.encode(image); 
    out.close(); 


替换为:

[java] view plaincopyprint?在CODE上查看代码片派生到我的代码片

    ImageIO.write(image,  "jpeg" , new File(targetImg)); 
    image.flush(); 

----
[javac] D:\work\mpa\hyjc2\src\hyjc\image\ImageUtil.java:87: 错误: 找不到符号

    [javac]             JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    [javac]             ^
    [javac]   符号:   类 JPEGImageEncoder

猜你喜欢

转载自mauersu.iteye.com/blog/2145314