首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > windows >

用windows phone统制wifi小车

2012-12-17 
用windows phone控制wifi小车目前只针对windows phone7.5做了测试,不知道wp8能不能用先上图: 放上视频获取

用windows phone控制wifi小车

目前只针对windows phone7.5做了测试,不知道wp8能不能用

先上图:

用windows phone统制wifi小车

用windows phone统制wifi小车

 

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

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)
            {

            }
        }


 

热点排行