java - pngcrush sample code snipet

395 views Asked by At

I am trying to use pngcrush to optimise my png image. I am able to run it on terminal with following command

$ pngcrush -brute -e "Optimize.png" filename.png

but i want achieve it from my Java program. How can I achieve it? I have googled it but not found any relevant info.

1

There are 1 answers

0
Stephan On BEST ANSWER

You can invoke the command from your program directly:

public class Main {
    public static void main(String[] args) {
        try {
            String[] command = {"pngcrush", "-brute, "-e", "Optimize.png", "filename.png"};
            Runtime.getRuntime().exec(command);
        } catch (java.io.IOException e) {
            e.printStackTrace();
        }
    }
}