views:

36

answers:

2

Hey all, weird question. My company has an application from another company that records an image taken by a camera connected via Ethernet. Their app is written in C++ and I've been trying to convert/hack it using Java.

I'm able to receive images, but the quality is not the same. The photo on top is from their app and the photo on bottom is from mine:

alt text

alt text

Any idea why those artifacts are showing up in my version of the app written in Java? It happens with both BMP and JPG images.

The way it works is just through sockets (both the C++ and Java versions)... a command is sent to capture an image and the camera responds by sending the data (bytes). I save a byte array then create a new BufferedImage from them:

// Create buffered image from bytes
image = ImageIO.read(new ByteArrayInputStream(imageBytes));

Thanks for any input or ideas.

+1  A: 

This looks like a palette problem, ie the numeric values of the individual pixels remain the same, but the table mapping those values onto actual RGB values may be messed up (actually, looking at the specific picture, it might even be that the source is BW and yours is color). My guess would be that the transmission is not the problem. Try sending a known bytestring to confirm that if you like, but I'd further concentrate on the image encoding.

Nicolas78
+1  A: 

Could it be a data type issue? What is the data format? (ints, shorts, unsigned shorts?)

static_rtti
Hmm... in the C++ version the image is being saved into an unsigned char array. In Java I'm reading it into a String that I concatenate as I read the data in line-by-line (to check for the end of data flag the camera sends). After I read it into the String, I convert the String to bytes. Maybe that's the issue? Might make a lot of sense actually.
Eric Jackson
Note the Java byte type is signed!
Thorbjørn Ravn Andersen
Turns out reading it into a String then doing .getBytes() isn't the same as reading it int by int into a byte[] array (with casting). It works now! This answer made me double check and investigate.
Eric Jackson