Following code gives org.im4java.core.CommandException: org.im4java.core.CommandException: return code: 1 I am trying to compare two colors. what is wrong in my code or what is the correct solution to compare colors.
ImageCommand compare=new ImageCommand();
IMOperation op = new IMOperation();
It's because ImageMagick's compare will return a non-zero exit code if the images are dissimilar. But the comparison should be working, the resulting difference image (3rd argument) is correctly generated.
It's however a problem for im4java because that's considered an error exit code, and there's no way as far as I know to tell im4java that it's not. See this discussion for more details.
You can work around it by catching the exception and ignoring it if the return code was 1 (compare should return 2 in case of error).