日期:2014-05-17 浏览次数:20993 次
目前只针对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;
});
&