0

Windows Phone 7.5 のスクリーンショットを撮り、TCP 経由で送信する方法に行き詰まっています。私はソケット プログラムと I/O の経験がなく、インターネット上のチュートリアルを通じてできることを行っています。これは私がやったことです。

以下のコードから、WP7.5 バックグラウンドで定期的に実行されている Jpeg としてエンコードされた TCP 経由で writeableBitMap を送信する方法に行き詰まっています。これにより、デスクトップ上のプログラムはそれを jpeg 画像として受け取り、ウィンドウを作成して表示できます電話からデスクトップへのストリーミング効果。

ソケット接続を処理するためのチュートリアルから作成したライブラリを使用した Windows Phone 7.5 アプリケーションのメインページ。

    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();
            }
        }
    }


}
4