出现原因:图像处理JPEGCodec类已经从Jdk1.7以后移除。
解决方法1:通过配置maven-compiler-plugin插件可以解决此问题。
插件中添加这个配置
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<verbose/>
<bootclasspath>${java.home}\lib\rt.jar;${java.home}\lib\jce.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
解决方法2 :代码更改
可能出现问题的代码:
- import java.awt.image.BufferedImage;
- //import com.sun.image.codec.jpeg.JPEGCodec;
- //import com.sun.image.codec.jpeg.JPEGImageEncoder;
- import javax.imageio.ImageIO;
修改后:
- static void saveImage(BufferedImage dstImage, String dstName) throws IOException {
- 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 */ );
- }