This isn t really an answer to your question to make pixel-perfect collision, but I want to say that it is a bad idea to make the fixtures depending on the images.
- Box2D doesn t support concave fixtures.
- Box2D (the original version in C++, I don t know how this works in JBox2D) has a limit to 8 vertices per polygon.
Because of these two reason, you might think to create one square fixture per pixel, but that is going to be very expensive in processing time.
In my almost finished game, I m defining my fixtures with a level editor.
Here is an excerpt of one of my levels (xml):
<body id="STONE" depth="13" angle="0.000000" type="static" x="7.939437" y="0.750494" tags="" >
<image id="stone_img" img="IMG_STONE" depth="0" x="-0.362081" y="0.526663" w="1.400000" h="1.600000" angle="0.000000" colorize="ffffffff"/>
<fixture id="" density="1.000000" friction="0.300000" restitution="0.300000" sensor="false" shape="rect" x="-0.188671" y="0.806253" w="1.000000" h="2.200000" angle="0.545597" tags="" />
<fixture id="" density="1.000000" friction="0.300000" restitution="0.300000" sensor="false" shape="rect" x="0.412080" y="-0.097607" w="1.000000" h="2.200000" angle="0.000000" tags="" />
</body>
I think this is the best way of working with Box2D.
Hopefully this inspires you :D