02-11-2010 08:08 AM
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?
02-11-2010 08:17 AM
http://www.coderholic.com/blackberry-webbitmapfiel
02-11-2010 08:47 AM
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?
02-11-2010 11:49 AM
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:
02-11-2010 12:14 PM - last edited on 02-11-2010 12:30 PM
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
) 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
. 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.
02-11-2010 01:27 PM
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.
02-11-2010 01:36 PM
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.