2012-04-10 11 views
0

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

以下のコードから、私はWP7.5バックグラウンドで定期的に動作するJpegとしてエンコードされたTCP上にwriteableBitMapを送信することができません。デスクトップ上のプログラムはjpegイメージとして受信できますデスクトップのストリーミング効果にWindows電話を作成して表示されます。

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


} 

答えて

関連する問題