2

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.

Sumit D
  • 401
  • 4
  • 15
  • 1
    I believe this is basically the same question: http://stackoverflow.com/questions/8496494/running-command-line-in-java – drew_w Dec 10 '13 at 13:33

1 Answers1

0

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();
        }
    }
}
Stephan
  • 41,764
  • 65
  • 238
  • 329