2009-06-11 73 views
1

我是J2ME技术的新手。我正在制作一个应用程序,它将使用蓝牙将文本和图像(通过http下载并存储到表单的ImageItem中)从客户端移动设备传输到服务器移动设备。使用的连接是SPP。我已经成功传送短信。但我无法传送图像。 任何人都可以帮助我通过蓝牙直接将图像传输到服务器移动,而不必将其保存到手机内存或存储卡。, 我会很感激你。J2me中的蓝牙文件传输

回答

2
 

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. 

+0

如果他访问的图像,然后他可能访问创建它的byte []数组的方法。这很可能是压缩格式,因此它比通过蓝牙发送更好,因为它将比getRGB()int数组小。 – funkybro 2009-06-18 17:50:54

0

那么,如果你的服务器移动使用蓝牙,并运行你写的应用程序,那么你可以创建自己的协议来做到这一点。

对于图像传输,最好发送通过HTTP下载的字节(并用于创建ImageItem),然后在服务器端接收它们并以相同的方式显示。

这样做时遇到的具体问题是什么?

funkybro

+0

喜funkybro, 可以为您提供链接到一些示例代码来实现,你在这里所讨论 – 2009-06-12 12:59:45

0

由于funkybro建议,您可以使用字节将图像传送到服务器上移动。为此,您需要打开已连接到蓝牙服务器移动设备的连接的输出流,然后将字节内容写入输出流。