Domanda

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.

È stato utile?

Soluzione

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();
        }
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top