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?

Recommended Answers

All 2 Replies

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);
fileStream.Close();

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.