我是靠谱客的博主 整齐小土豆,这篇文章主要介绍程序包com.sun.image.codec.jpeg不存在解决方法,现在分享给大家,希望可以做个参考。

          阿里云低价服务器1折特惠,优惠爽翻天,点我立即低价购买

一些老的Java代码在JDK1.7下编译会报错,比如这个:程序包com.sun.image.codec.jpeg不存在。
     JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);

JPEGImageEncoder类是SUN公司私有类

    一般出现在这样的代码段中:
        FileOutputStream out = new FileOutputStream(dstName);
         JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
         encoder.encode(dstImage);

    改写成:

        String formatName = dstName.substring(dstName.lastIndexOf(".") + 1);
         //FileOutputStream out = new FileOutputStream(dstName);
         //JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
         //encoder.encode(dstImage);
         ImageIO.write(dstImage, /*"GIF"*/ formatName /* format desired */ , new File(dstName) /* target */ );
都使用统一的ImageIO进行图像格式文件的读写,没有必要使用过时的实现类JPEGImageEncoder类。

          阿里云低价服务器1折特惠,优惠爽翻天,点我立即低价购买

最后

以上就是整齐小土豆最近收集整理的关于程序包com.sun.image.codec.jpeg不存在解决方法的全部内容,更多相关程序包com内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(140)

评论列表共有 0 条评论

立即
投稿
返回
顶部