ImageMagick convert command not working through java

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Newbee
Posts: 3
Joined: 2014-05-05T12:29:16-07:00
Authentication code: 6789

ImageMagick convert command not working through java

Post by Newbee » 2014-06-22T10:04:32-07:00

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.

User avatar
whugemann
Posts: 294
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: ImageMagick convert command not working through java

Post by whugemann » 2014-06-27T03:06:19-07:00

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\""
Wolfgang Hugemann

Post Reply