您的位置:首页 > 其它

用windows phone控制wifi小车

2012-12-07 23:16 148 查看
目前只针对windows phone7.5做了测试,不知道wp8能不能用

先上图:





放上视频获取的主要代码:

using System.Windows.Media.Imaging;

using System.Threading;

using System.IO;

using System.Text;

定义:

BitmapImage bs = new BitmapImage();

在load事件里开一个线程

thread = new Thread(new ThreadStart(recVideo));

thread.Start();

recVideo方法

private void recVideo()

{

string sourceURL = "远程图片流地址";

while (true)

{

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri(sourceURL));

req.BeginGetResponse(new AsyncCallback(resResult), req);

}

}

private void resResult(IAsyncResult ir)

{

try

{

byte[] buffer = new byte[1000000];

int read, total = 0;

HttpWebRequest req = ir.AsyncState as HttpWebRequest;

WebResponse resp = req.EndGetResponse(ir);

Stream stream = resp.GetResponseStream();

while ((read = stream.Read(buffer, total, 100)) != 0)

{

total += read;

}

Dispatcher.BeginInvoke(() =>

{

bs.SetSource(new MemoryStream(buffer, 0, total));

image1.Source = bs;

});

}

catch (Exception e)

{

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: