libpng warning: iCCP: known incorrect sRGB profile java
时间: 2023-11-21 15:58:05 浏览: 55
解决 libpng warning: iCCP: known incorrect sRGB profile
当使用Java处理PNG图片时,可能会出现“libpng warning: iCCP: known incorrect sRGB profile”的警告。这是因为PNG图片中的ICC颜色配置文件不正确导致的。解决这个问题的方法如下:
1.使用ImageIO库加载图片并重新保存:
```java
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class PNGTest {
public static void main(String[] args) throws IOException {
File input = new File("input.png");
BufferedImage image = ImageIO.read(input);
File output = new File("output.png");
ImageIO.write(image, "png", output);
}
}
```
2.使用Apache Commons Imaging库加载图片并重新保存:
```java
import java.io.File;
import java.io.IOException;
import org.apache.commons.imaging.ImageReadException;
import org.apache.commons.imaging.ImageWriteException;
import org.apache.commons.imaging.Imaging;
import org.apache.commons.imaging.common.ImageMetadata;
import org.apache.commons.imaging.formats.png.PngImageMetadata;
import org.apache.commons.imaging.formats.png.PngImageParser;
import org.apache.commons.imaging.formats.png.PngImageWriteParam;
public class PNGTest {
public static void main(String[] args) throws IOException, ImageReadException, ImageWriteException {
File input = new File("input.png");
File output = new File("output.png");
PngImageParser parser = new PngImageParser();
ImageMetadata metadata = Imaging.getMetadata(input);
PngImageMetadata pngMetadata = (PngImageMetadata) metadata;
PngImageWriteParam writeParam = new PngImageWriteParam();
writeParam.setGamma(pngMetadata.getGamma());
Imaging.writeImage(parser.getBufferedImage(Imaging.getStream(input)), output, writeParam);
}
}
```
阅读全文