-3
我能夠通過藍牙在PC和android之間進行數據傳輸。但是現在我想發送大小約80KB的圖像文件。當我發送圖像時,只有一部分被轉移,但不完全是 。有誰知道如何實現這一目標?我正在使用TCP並在C#平臺上工作。如何通過藍牙從PC發送圖像到Android使用C#
string fileName = "send.png";
string filePath = @"C:\Users\Asus 53s\Desktop\"; //path
byte[] fileNameByte = Encoding.ASCII.GetBytes(fileName);
byte[] fileData = File.ReadAllBytes(filePath + fileName);
byte[] clientData = new byte[4 + fileNameByte.Length + fileData.Length];
byte[] fileNameLen = BitConverter.GetBytes(fileNameByte.Length);
fileNameLen.CopyTo(clientData,0);
fileNameByte.CopyTo(clientData,4);
fileData.CopyTo(clientData,4+fileNameByte.Length);
sendMessage(clientData);
}
public Boolean sendMessage(byte[] msg)
{
{
if (!msg.Equals(""))
{
UTF8Encoding encoder = new UTF8Encoding();
NetworkStream stream = me.GetStream();
stream.Write(encoder.GetBytes(msg + "\n"), 0, (msg).Length);
stream.Flush();
}
}
沒有發佈任何代碼,您如何期待任何人知道可能有什麼錯! – Lloyd 2012-03-02 15:33:32
對不起,我粘貼了我現在使用的代碼。 – ragz 2012-03-02 16:15:43
收到多少圖像。您可能必須以小塊形式發送。你做了什麼來弄清楚你的代碼不工作的原因。取決於藍牙的版本,它可能相當不可靠。 – 2012-03-02 16:18:12