Page 1 of 1

ImageMagick convert command not working through java

Posted: 2014-06-22T10:04:32-07:00
by Newbee
Hello ,

I am using ImageMagick-6.8.9-Q16 version on windows and trying to run the compare and convert command through java.

Currently I am using the convert command to color some region in an image. Command below.

Code: Select all

String[] command = {"cmd.exe","/c",	"cd \"C:\\Program Files\\ImageMagick-6.8.9-Q16\" && convert \"D:\\ImageComparison\\Copy\\All_Apps_Copy1.bmp\" -fill black -draw \"rectangle 287,11  347,35 rectangle 92,14 199,36 rectangle 613,432 628,448\" \"D:\\ImageComparison\\Copy\\All_Apps_Copy11.bmp\"" };
	ProcessBuilder pb = new ProcessBuilder(command);
		Process process = pb.start();
		int row = process.waitFor();
It works find and gives the desired result. However I want to pass the reference and resultant image in the command as a argument.

Code: Select all

String command[] = {"C:\\Program Files\\ImageMagick-6.8.9-Q16\\convert.exe","D:\\ImageComparison\\Copy\\All_Apps_Copy1.bmp" ,"-fill black -draw \"rectangle  287,11  347,35\"",  \"D:\\ImageComparison\\Copy\\All_Apps_Copy11.bmp\""};
It doesn't seem to work. Can anyone help me to make this work.

Re: ImageMagick convert command not working through java

Posted: 2014-06-27T03:06:19-07:00
by whugemann
IMHO, this has little to do with IM, but with Java. Your escaping of the double quotes in the seond filename seems to be wrong:

Code: Select all

\"D:\\ImageComparison\\Copy\\All_Apps_Copy11.bmp\""
should either be

Code: Select all

"D:\\ImageComparison\\Copy\\All_Apps_Copy11.bmp"
or

Code: Select all

"\"D:\\ImageComparison\\Copy\\All_Apps_Copy11.bmp\""