views:

852

answers:

3

hi, I am new to the J2ME technology. And I am making an application which will transfer the text and image(downloaded through http and stored into an ImageItem of a form) from a client mobile to the server mobile using bluetooth. The connection used is SPP. I have succeded to transfer the text message. But I am unable to transfer the image. Can anyone help me to transfer the image to the server mobile through bluetooth directly without saving it into the phone memory or memory card., I would be thankful to you.

A: 

Well if your server mobile is using Bluetooth and also running an application written by you, then you can create your own protocol to do this.

For image transfer, it is best to send the bytes that were downloaded over HTTP (and used to create the ImageItem), then receive them at the server end and display in the same way.

What is the specific problem you're encountering while doing this?

funkybro

funkybro
hi funkybro,can you provide links to some sample code to implement the method that you are discussing here
Sumit Ghosh
A: 

As funkybro suggested, you can use the bytes to transfer the image to the server mobile. For that you need to can just open the output stream of the connection that you have made to the bluetooth server mobile and then write the byte contents on to the output stream.

Ram
+1  A: 

javax.microedition.lcdui.Image.getRGB() is the method you are looking for.

If myImageItem is your ImageItem object, the code would look like this:

------------

Image myImage = myImageItem.getImage();
int[] myImageInts = new int[myImage.getHeight() * myImage.getWidth()];
// Beware of OutOfMemoryError here.

myImage.getRGB(myImageInts, 0, myImageInts.length, 0, 0,
                                       myImage.getWidth(), myImage.getHeight());

------------

You can then convert each int in the array into 4 bytes
(in the correct order please)
and feed these to your Connection's OutputStream.

Alternatively, DataOutputStream.writeInt() does the conversion for you.

QuickRecipesOnSymbianOS
If he has access to the Image then he probably has access to the byte[] array that created it. This is most likely in a compressed format and is therefore better for sending over bluetooth as it will be smaller than the getRGB() int array.
funkybro
True enough but the question only mentionned an ImageItem so I thought it best to not assume anything.
QuickRecipesOnSymbianOS