Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
ShadowMare
Posts: 47
Registered: 05-06-2009

receiving and creating a bitmap via a socket connection

Hi there!

 

 

I'm trying to receive a .jpg file via a socket connection. But when I want to create a bitmap out of that it throws a IllegalArgumentException with null as message.

 

It is transmitted via the following format:

<size of the byte array>byteArray

 

Basically it can be reduced to the following:

_in is an InputStream.

 

 

// at first it reads how much bytes the image has by parsing <size>

byte[] byteInput = new byte[size];
_in.read(byteInput);
Bitmap temp = Bitmap.createBitmapFromBytes(byteInput, 0, byteInput.length, 1)

// IllegalArgumentException is thrown in the last line

 I'm using OS 5.0!

Can you help me?

 

Please use plain text.
Developer
simon_hain
Posts: 10,780
Registered: 07-29-2008
My Carrier: O2 Germany

Re: receiving and creating a bitmap via a socket connection

http://www.coderholic.com/blackberry-webbitmapfield/

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.

peter_strange wrote:
"This process should happen traumatically for you in both JDE and Eclipse."
Please use plain text.
Developer
ShadowMare
Posts: 47
Registered: 05-06-2009

Re: receiving and creating a bitmap via a socket connection

Thank you for your reply.

 

I changed my read code and the code which makes a bitmap out of the string to the one provided in the link but it throws the same exception! It seems that my old code received the same as your code.

 

What am I doing wrong?

Please use plain text.
Developer
peter_strange
Posts: 14,614
Registered: 07-14-2008

Re: receiving and creating a bitmap via a socket connection

What format is the file you are sending (png or jpg)?

 

Have you dumped out the bytes you receive to make absolutely sure that it is the same as the data on the Server.  You might find this sample code useful:

http://supportforums.blackberry.com/t5/Java-Development/Convert-Utf-8-encofed-text-to-Hex-Decimal/m-...

Please use plain text.
Developer
ShadowMare
Posts: 47
Registered: 05-06-2009

Re: receiving and creating a bitmap via a socket connection

[ Edited ]

Thank you for your reply, Peter!

 

Im sending a .jpg file. I'm quite sure those are the "same" bytes, but I have no good idea (the one below isn't good I think :smileyvery-happy:) to prove that.

 

The receiving part is java and the server part is c#.net. The main problem is to get those received byte out of the java application again :smileytongue:. I tried to build a string out of that bytes using String(byteInput) that gives me:

 

ÿÃ\u0098ÿà\u0000\u0010JFIF\u000...

where it was on the server side:

ÿØÿà JFIF  ` `...

Is that correct?

 

//Edit: I just noticed that an old version of my server code (non .NET) is working with my java code. So I think I have to look for the problem in the new c#.net code. Please tell me if you have an idea of what I'm doing wrong.

Please use plain text.
Developer
peter_strange
Posts: 14,614
Registered: 07-14-2008

Re: receiving and creating a bitmap via a socket connection

Sorry, I am not a c# coder (though I have done some).

 

However normally the problem you get here is people trying to process byte data in a String.  You should send the raw data you read.  This might be a problem with the c# method of packaging data, you could use a sendString method when you really want a sendBytes.  Just guessing. 

 

Re dumping out the bytes, the link I gave in my previous post was supposed to help with that.  You must dump out each byte in hex, so that if the byte contains

0x00

you will see as output

"00"

trying to build a String from the bytes is not valid - they are binary data.

Please use plain text.
Developer
ShadowMare
Posts: 47
Registered: 05-06-2009

Re: receiving and creating a bitmap via a socket connection

Thank your for pointing that out, I already had a bad feeling when I tried to make a string out of the byte array.

I'm trying to communicate via a TCP socket which is working fine for plain text.

Trying to use the designated method to send a byte array gives me the same "unparsable" thing as the send string method. Probably my code is not reading the file correctly but this is the same as the method in my old code where the received image is fine. I'm confused.

Please use plain text.