我想使用immajick或使用im4java的ImageMagick压缩png,任何人都可以帮助我吗?我找到了
package example;
import com.googlecode.pngtastic.core.PngImage;
import com.googlecode.pngtastic.core.PngOptimizer;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
/**
* Example pngtastic image optimization usage from java
*/
public class Test {
public static void main(String[] args) throws Exception {
// load png image from a file
final InputStream in = new BufferedInputStream(new FileInputStream("/input.png"));
final PngImage image = new PngImage(in);
// optimize
final PngOptimizer optimizer = new PngOptimizer();
final PngImage optimizedImage = optimizer.optimize(image);
// export the optimized image to a new file
final ByteArrayOutputStream optimizedBytes = new ByteArrayOutputStream();
optimizedImage.writeDataOutputStream(optimizedBytes);
optimizedImage.export("/output.png", optimizedBytes.toByteArray());
}
}
使用pngtastic,但在压缩198.3kB之前和压缩后的非常小的图像179.6kB
答案 0 :(得分:0)
我在linux上发现它是pngnq,你可以安装它并在java中使用Runtime.getRuntime().exec("pngnq <file png>");