Hi guys,
I'm currently doing a J2ME application that gets a JPEG image and sends it's bytes to a C# server via sockets. In the J2ME application, I can re-convert the bytes I sent to an Image and view it. On the server side, however, the SAME bytes cannot create an image using Image.FromStream() Method. Is there some meta-data I need to include to successfully create an Image in C# created from Java?

8 Years
Discussion Span
Last Post by Rombosia

Here's the code I use without any problem when passing byte arrays back and forth from java to c#

//Assign these some values
byte[] byteImage;
string savePath;

FileStream fileStream = new FileStream(savePath, FileMode.Create);
//attempts to write file to local machine
fileStream.Write(byteImage, 0, byteImage.Length);

I stumbled upon the cause of the problem. I was using String.getBytes() method to convert my string that contained image data. This gets bytes as ascii bytes, which corrupts Unicode bytes. I tried getting the string that contains image data and converting each character to a byte. It then worked fine.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.