【问题标题】:Taking screenshot of windows phone 7.5 and sending over through TCP截取windows phone 7.5的截图并通过TCP发送
【发布时间】:2012-04-10 15:43:33
【问题描述】:

我被困在如何截取我的 windows phone 7.5 的屏幕截图并通过 TCP 发送它。我没有做套接字程序和 I/O 的经验,我正在通过互联网上的教程做我能做的事情。这就是我所做的。

从下面的代码中,我陷入了如何通过 TCP 发送 writeableBitMap 编码为在 WP7.5 后台定期运行的 Jpeg 的问题,从而桌面上的程序将其作为 jpeg 图像接收,以便显示创建 Windows Phone 到桌面的流媒体效果。

我的 windows phone 7.5 应用程序的 mainPage 使用了我根据教程创建的用于处理套接字连接的库。

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone;
using System.Windows.Media;
using System.IO;

namespace helloworld
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        SocketLibrary.socketLib sl = new SocketLibrary.socketLib();
        private string hostIP = "127.0.0.1";
        public MainPage()
        {
            InitializeComponent();
        }

        private void btnConnect_Click(object sender, RoutedEventArgs e)
        {
            bool retVal;

            retVal = sl.EstablishTCPConnection(hostIP);

            WriteableBitmap bmpCurrentScreenImage = new WriteableBitmap((int)this.ActualWidth, (int)this.ActualHeight);

            var ms = new MemoryStream();
            // Send the picture.
            bmpCurrentScreenImage.SaveJpeg(ms, bmpCurrentScreenImage.PixelWidth, bmpCurrentScreenImage.PixelHeight, 0, 90);
            ms.Seek(0, SeekOrigin.Begin);
            retVal = sl.Send(ms);

            sl.CloseSocket();
        }


    }
}

套接字库

   namespace SocketLibrary
{
    public class socketLib
    {
        Socket s = null;
        static ManualResetEvent done = new ManualResetEvent(false);
        private Int16 portNo = 3334;

        public socketLib()
        {


        }
        public bool EstablishTCPConnection(string host)
        {
            s = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
            ProtocolType.Tcp);
            SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
            socketEventArg.RemoteEndPoint = new DnsEndPoint(host, portNo);
            socketEventArg.Completed += new
            EventHandler<SocketAsyncEventArgs>(delegate(object o, SocketAsyncEventArgs e)
            {
                done.Set();
            });
            done.Reset();
            s.ConnectAsync(socketEventArg);
            return done.WaitOne(10000);
        }

        public bool Send(MemoryStream data)
        {
            byte[] msData = data.ToArray();
            if (s != null)
            {
                SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
                socketEventArg.RemoteEndPoint = s.RemoteEndPoint;
                socketEventArg.UserToken = null;

                socketEventArg.Completed += new
                EventHandler<SocketAsyncEventArgs>(delegate(object o, SocketAsyncEventArgs e)
                {
                    done.Set();
                });

                socketEventArg.SetBuffer(msData, 0, msData.Length);
                done.Reset();
                s.SendAsync(socketEventArg);
                return done.WaitOne(10000);
            }
            return false;
        }

        public void CloseSocket()
        {
            if (s != null)
            {
                s.Close();
            }
        }
    }


}

【问题讨论】:

    标签: windows-phone-7 windows-phone-7.1


    【解决方案1】:
    猜你喜欢
    • 2013-06-28
    • 2017-02-25
    • 1970-01-01
    • 2011-10-04
    • 1970-01-01
    • 2014-04-17
    • 1970-01-01
    • 2019-05-28
    • 1970-01-01
    相关资源
    最近更新 更多