//private async void ShutterButton_Click(object sender, EventArgs eventArgs) //{ // if (cam != null) // { // CameraCaptureSequence captureSequence = cam.CreateCaptureSequence(1); // MemoryStream captureStream = new MemoryStream(); // captureSequence.Frames[0].CaptureStream = captureStream.AsOutputStream(); // await cam.PrepareCaptureSequenceAsync(captureSequence); // await captureSequence.StartCaptureAsync(); // captureStream.Seek(0, SeekOrigin.Begin); // byte[] buffer = new byte[captureStream.Length]; // captureStream.Read(buffer, 0, buffer.Length); // phoneService.BeginSendImage(++imageSeqeuenceNumber, buffer, SendImageCompleted, null); // //timer.Start(); // // Dispatcher.BeginInvoke(timer.Stop); // // try // // { // // //Debug.Assert(cam.FlashMode == FlashMode.Off); // // cam.FlashMode = FlashMode.Off; // // cam.CaptureImage(); // // } // // catch (Exception ex) // // { // // this.Dispatcher.BeginInvoke(delegate() // // { // // // Cannot capture an image until the previous capture has completed. // // txtDebug.Text = ex.Message; // // }); // // } // } //} //void cam_CaptureCompleted(object sender, CameraOperationCompletedEventArgs e) //{ // // Increments the savedCounter variable used for generating JPEG file names. // savedCounter++; //} // Informs when full resolution picture has been taken, saves to local media library and isolated storage. //void cam_CaptureImageAvailable(object sender, ContentReadyEventArgs e) //{ // //string fileName = savedCounter + ".jpg"; // if (phoneService != null) // { // //SocketAsyncEventArgs se = new SocketAsyncEventArgs(); // //se.Buffer = new byte[]; // e.ImageStream.Seek(0, SeekOrigin.Begin); // byte[] buffer = new byte[e.ImageStream.Length]; // e.ImageStream.Read(buffer, 0, buffer.Length); // //e.ImageStream.ReadAsync(buffer, 0, buffer.Length); // //se.SetBuffer(buffer, 0, buffer.Length); // //streamScoket.SendAsync(se); // e.ImageStream.Close(); // IAsyncResult r = phoneService.BeginSendImage(++imageSeqeuenceNumber, buffer, SendImageCompleted, null); // //phoneService.EndSendImage(r); // //Dispatcher.BeginInvoke(timer.Start); // } // //try // //{ // Write message to the UI thread. // // Deployment.Current.Dispatcher.BeginInvoke(delegate() // // { // // txtDebug.Text = "Captured image available, saving picture."; // // }); // // // Save picture to the library camera roll. // // library.SavePictureToCameraRoll(fileName, e.ImageStream); // // // Write message to the UI thread. // // Deployment.Current.Dispatcher.BeginInvoke(delegate() // // { // // txtDebug.Text = "Picture has been saved to camera roll."; // // }); // // // Set the position of the stream back to start // // e.ImageStream.Seek(0, SeekOrigin.Begin); // // // Save picture as JPEG to isolated storage. // // using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication()) // // { // // using (IsolatedStorageFileStream targetStream = isStore.OpenFile(fileName, FileMode.Create, FileAccess.Write)) // // { // // // Initialize the buffer for 4KB disk pages. // // byte[] readBuffer = new byte[4096]; // // int bytesRead = -1; // // // Copy the image to isolated storage. // // while ((bytesRead = e.ImageStream.Read(readBuffer, 0, readBuffer.Length)) > 0) // // { // // targetStream.Write(readBuffer, 0, bytesRead); // // } // // } // // } // // // Write message to the UI thread. // // Deployment.Current.Dispatcher.BeginInvoke(delegate() // // { // // txtDebug.Text = "Picture has been saved to isolated storage."; // // }); // //} // //finally // //{ // // // Close image stream // // e.ImageStream.Close(); // //} //} private void SendImageCompleted(IAsyncResult ar) { try { phoneService.EndSendImage(ar); } catch (Exception e) { Delegate d = new Func <Exception, string>(exc => txtDebug.Text = exc.Message); this.Dispatcher.BeginInvoke(d, e); } finally { lastSendImageTick = Environment.TickCount; sendImageInterval -= 100; Dispatcher.BeginInvoke(() => { txtDebug.Text = "sendImageInterval=" + sendImageInterval; }); } }