https://products.aspose.com/imaging/ 文档 API 文档 Java APIs to create, manipulate or convert different format images in any application based on Java SE or EE. 收费的!
apng 压缩
安装
<repositories>
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-imaging</artifactId>
<version>23.10</version>
<classifier>jdk16</classifier>
</dependency>
<!-- if you need a documentation, please add the following dependency. For example it could be useful for IDE. -->
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-imaging</artifactId>
<version>23.10</version>
<classifier>javadoc</classifier>
</dependency>
</dependencies>After performing above steps, Aspose.Imaging for Java dependency will finally be defined in your Maven Project.
aspose
public static void addCompression(String inputFile, String outputFile ) {
try (Image image = Image.load(inputFile)) {
ApngOptions options = new ApngOptions();
options.setCompressionLevel(9);
options.setProgressive(true);
options.setColorType(PngColorType.IndexedColor);
options.setPalette(ColorPaletteHelper.getCloseImagePalette((RasterImage) image, 1 << 8));
image.save(outputFile, options);
}
}
public static void main(String[] args) {
String input = "E:\\content-for-work\\202310深汕建设项目\\img\\result_ori.png";
String output = "E:\\content-for-work\\202310深汕建设项目\\img\\result_comp.png";
addCompression(input, output);
}