示例#1
0
        void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
        {
            string fileName = savedCounter + ".jpg";

            try
            {
                e.ImageStream.Seek(0, SeekOrigin.Begin);

                using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (var targetStream = isoStore.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 the local folder.
                        while ((bytesRead = e.ImageStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
                        {
                            targetStream.Write(readBuffer, 0, bytesRead);
                        }
                    }
                }
            }
            finally
            {
                e.ImageStream.Close();
            }
        }
示例#2
0
        void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
        {
            try
            {
                e.ImageStream.Seek(0, SeekOrigin.Begin);
                MemoryStream ms1 = new MemoryStream();
                e.ImageStream.CopyTo(ms1);

                // Write message to the UI thread.
                Deployment.Current.Dispatcher.BeginInvoke(delegate()
                {
                    try
                    {
                        bool isPortait = (this.Orientation == PageOrientation.Portrait || this.Orientation == PageOrientation.PortraitDown || this.Orientation == PageOrientation.PortraitUp);
                        PictureCache.Current.Save(ms1, Navigate.PictureFilename, Navigate.PictureFoodId, isPortait);
                        Navigate.BackFromOther();
                    }
                    catch (Exception ex) { LittleWatson.ReportException(ex); }
                    finally
                    {
                        ms1.Dispose();
                    }
                });
            }
            catch (Exception ex) { LittleWatson.ReportException(ex); }
            finally
            {
                // Close image stream
                e.ImageStream.Close();
            }
        }
示例#3
0
 void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
 {
     Image = e.ImageStream;
     DispatcherHelper.CheckBeginInvokeOnUI(() =>
     {
         App.RootFrame.Navigate(new Uri("/View/SendPage.xaml", UriKind.RelativeOrAbsolute));
     });
 }
        // Informs when full resolution photo has been taken, saves to local media library and the local folder.
        void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
        {
            try
            {   // Write message to the UI thread.
                Deployment.Current.Dispatcher.BeginInvoke(delegate()
                {
                    txtDebug.Text = "Captured image available, saving photo.";
                });

                // Save photo to the media library camera roll.

                /* library.SavePictureToCameraRoll(fileName, e.ImageStream);
                 *
                 * // Write message to the UI thread.
                 * Deployment.Current.Dispatcher.BeginInvoke(delegate()
                 * {
                 *   txtDebug.Text = "Photo has been saved to camera roll.";
                 *
                 * });*/

                // Set the position of the stream back to start
                e.ImageStream.Seek(0, SeekOrigin.Begin);

                // Save photo as JPEG to the local folder.
                using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    string fileName = "files\\" + DateTime.Now.ToString("yymmddhhmmss") + ".jpg";
                    if (!isStore.DirectoryExists("files"))
                    {
                        isStore.CreateDirectory("files");
                    }
                    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 the local folder.
                        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 = "Photo has been saved to the local folder.";
                });
            }
            finally
            {
                // Close image stream
                e.ImageStream.Close();
            }
        }
示例#5
0
        //Informs when full resolution picture has been taken and stores it
        void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
        {
            string fileName = savedCounter + ".jpg";

            try
            {   //Write message to the UI
                Deployment.Current.Dispatcher.BeginInvoke(delegate()
                {
                    txtDebug.Text = "Captured image available, saving picture...";
                });

                //Save picture camera roll
                library.SavePictureToCameraRoll(fileName, e.ImageStream);

                //Write message UI
                Deployment.Current.Dispatcher.BeginInvoke(delegate()
                {
                    txtDebug.Text = "Picture has been saved to camera roll...";
                });

                //Set position of stream back to start
                e.ImageStream.Seek(0, SeekOrigin.Begin);

                //Save picture as JPEG
                using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (IsolatedStorageFileStream targetStream = isStore.OpenFile(fileName, FileMode.Create, FileAccess.Write))
                    {
                        //Initialize buffer for 4KB disk pages
                        byte[] readBuffer = new byte[4096];
                        int    bytesRead  = -1;

                        //Store image
                        while ((bytesRead = e.ImageStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
                        {
                            targetStream.Write(readBuffer, 0, bytesRead);
                        }
                    }
                }

                //Write message to UI
                Deployment.Current.Dispatcher.BeginInvoke(delegate()
                {
                    txtDebug.Text = "Picture taken";
                });
            }
            finally
            {
                //Close image stream
                e.ImageStream.Close();
            }
        }
示例#6
0
        void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
        {
            photoCounter++;
            string fileName = photoCounter + ".jpg";

            Deployment.Current.Dispatcher.BeginInvoke(delegate()
            {
                txtMessage.Text = "Captured image available, saving picture.";
            });
            library.SavePictureToCameraRoll(fileName, e.ImageStream);
            Deployment.Current.Dispatcher.BeginInvoke(delegate()
            {
                txtMessage.Text = "Picture has been saved to camera roll.";
            });
        }
示例#7
0
        private void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
        {
            if (m_sFnDtNext.Length == 0)
            {
                DateTime dNow = DateTime.Now;
                m_sFnDtNext = dNow.Year.ToString() + RscUtils.pad60(dNow.Month)
                              + RscUtils.pad60(dNow.Day) + "_" + RscUtils.pad60(dNow.Hour) + RscUtils.pad60(dNow.Minute)
                              + RscUtils.pad60(dNow.Second);
            }

            if (m_bSaveToMediaLibrary)
            {
                MediaLibrary media = new MediaLibrary();
                media.SavePicture(m_sFnDtNext, e.ImageStream);

                e.ImageStream.Seek(0, System.IO.SeekOrigin.Begin);
            }
            else
            {
                RscStore store = new RscStore();

                string fName = RscKnownFolders.GetMediaPath("DCIM") + "\\" + m_sFnDtNext + ".jpg";
                int    iCnt  = 0;
                for (;;)
                {
                    if (!store.FileExists(fName))
                    {
                        break;
                    }
                    iCnt++;
                    fName = RscKnownFolders.GetMediaPath("DCIM") + "\\" + m_sFnDtNext + "_" + iCnt.ToString() + ".jpg";
                }

                System.IO.Stream stream = store.CreateFile(fName);
                // Initialize the buffer for 4KB disk pages.
                byte[] readBuffer = new byte[4096];
                int    bytesRead  = -1;
                // Copy the thumbnail to the local folder.
                while ((bytesRead = e.ImageStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
                {
                    stream.Write(readBuffer, 0, bytesRead);
                }
                stream.Close();
            }
        }
示例#8
0
        //Get the picture and try to decypher it using the database.
        private void CameraPictureReady(object sender, Microsoft.Devices.ContentReadyEventArgs e)
        {
            Stream image = e.ImageStream;

            Dispatcher.BeginInvoke(() =>
            {
                // setting the image in the display and start scanning in the background
                var bmp = new BitmapImage();
                bmp.SetSource(image);
                var tempbmp = new WriteableBitmap(bmp);

                int startX = tempbmp.PixelWidth / 5;
                int startY = tempbmp.PixelHeight / 5;

                var final = tempbmp.Crop(startX, startY, startX * 3, startY * 3);
                scannerWorker.RunWorkerAsync(final);
            });
        }
示例#9
0
        void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
        {
            Deployment.Current.Dispatcher.BeginInvoke(delegate()
            {
                BitmapImage bi = new BitmapImage();
                bi.SetSource(e.ImageStream);
                WriteableBitmap wb = new WriteableBitmap(bi);

                uint filter = 0xFFC29670;
                byte fR     = (byte)((filter & 0x00FF0000) >> 16);
                byte fG     = (byte)((filter & 0x0000FF00) >> 8);
                byte fB     = (byte)(filter & 0x000000FF);
                for (int pixel = 0; pixel < wb.Pixels.Length; pixel++)
                {
                    int color        = wb.Pixels[pixel];
                    byte A           = (byte)((color & 0xFF000000) >> 24);
                    byte R           = (byte)((color & 0x00FF0000) >> 16);
                    R                = (R > fR) ? fR : R;
                    byte G           = (byte)((color & 0x0000FF00) >> 8);
                    G                = (G > fG) ? fG : G;
                    byte B           = (byte)(color & 0x000000FF);
                    B                = (B > fB) ? fB : B;
                    color            = (A << 24) | (R << 16) | (G << 8) | B;
                    wb.Pixels[pixel] = color;
                }

                String tempJPEG = "TempJPEG";
                var store       = IsolatedStorageFile.GetUserStoreForApplication();
                if (store.FileExists(tempJPEG))
                {
                    store.DeleteFile(tempJPEG);
                }
                IsolatedStorageFileStream stream = store.CreateFile(tempJPEG);
                Extensions.SaveJpeg(wb, stream, wb.PixelWidth, wb.PixelHeight, 0, 85);
                stream.Close();

                string fileName = String.Format("sepia_%s.jpg", new DateTime().ToString("yyyyMMddhhmmss"));
                stream          = store.OpenFile(tempJPEG, FileMode.Open, FileAccess.Read);
                library.SavePictureToCameraRoll(fileName, stream);
                stream.Close();

                showNotice("Picture has been saved to camera roll.");
            });
        }
示例#10
0
        // Informs when full resolution picture has been taken, saves to local media library and isolated storage.
        void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
        {
            string fileName = String.Format("Ajapaik_{0:yyyy-MM-dd_hh-mm-ss-tt}.jpg",
                                            DateTime.Now);

            try
            {
                // Save picture to the library camera roll.
                library.SavePictureToCameraRoll(fileName, e.ImageStream);

                // Set the position of the stream back to start
                e.ImageStream.Seek(0, SeekOrigin.Begin);

                // Save picture as JPEG to isolated storage.
                App.Settings.PhotoByUser = new MemoryStream();
                var targetStream = App.Settings.PhotoByUser;
                // 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);
                }

                this.Dispatcher.BeginInvoke(delegate()
                {
                    // Write message.
                    //txtDebug.Text = "Camera initialized.";
                    //isCameraInitialized = true;
                    NavigationService.Navigate(new Uri("/Views/AcceptPhotoView.xaml", UriKind.Relative));
                });
            }
            finally
            {
                // Close image stream
                e.ImageStream.Close();
            }
        }
        // Informs when full resolution photo has been taken, saves to local media library and the local folder.
        void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
        {
            try
            {
                // e.ImageStream.Seek(0, SeekOrigin.Begin);

                byte[] image = new byte[e.ImageStream.Length];
                e.ImageStream.Read(image, 0, image.Length);

                this.Dispatcher.BeginInvoke(delegate()
                {
                    ShutterButton.IsEnabled = false;
                });
                string url = meeting.server.address + "/api/upload/" + meeting.server.login + "/" + meeting.server.sid + "/" + meeting.serverMeetingID + "/" + DateTime.Now.ToString("yyMMddHHmmss") + ".jpg";
                System.Diagnostics.Debug.WriteLine(url);
                new HttpPutRequest <StatusReasonOutput>(url, addPhotoCallback, image, (int)e.ImageStream.Length);
            }
            finally
            {
                e.ImageStream.Close();
            }
        }
示例#12
0
        // AACODE: Informs when full resolution photo has been taken, saves to variable App.gCapturedImage
        void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
        {
            string fileName = App.gSavedCounter + ".jpg";

            try
            {
                // Write message to the UI thread.
                Deployment.Current.Dispatcher.BeginInvoke(delegate()
                {
                    //txtDebug.Text = "Captured image available";
                });

                // AACODE: Passed this code to UI thread because it was causing invalid cross-thread exception
                Deployment.Current.Dispatcher.BeginInvoke(delegate()
                {
                    // Load the captured image stream to the global gCapturedImage variable
                    App.gCapturedImage     = new WriteableBitmap((int)cam.Resolution.Width, (int)cam.Resolution.Height);
                    e.ImageStream.Position = 0;
                    App.gCapturedImage.LoadJpeg(e.ImageStream);
                    e.ImageStream.Close();

                    // If photo has been taken, navigates to PreviewPhoto Page.
                    if (App.gBACK_KEY_NAVIGATION == 0)
                    {
                        App.gFrom   = "TakePhotoPage";
                        App.gAction = "PreviewPhoto";
                        NavigationService.GoBack();
                    }
                    else
                    {
                        NavigationService.Navigate(new Uri(App.GetDynamicUri("TakePhotoPage", "PreviewPhoto"), UriKind.Relative));
                    }
                });
            }
            catch (Exception ex)
            {
                // TODO: Add error handling
            }
        }
示例#13
0
        // Informs when full resolution picture has been taken, saves to local media library and isolated storage.
        void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
        {
            string fileName = patientid + "_" + timestamp + ".jpg";

            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.";

                    viewfinderCanvas.Visibility = Visibility.Collapsed;

                    IsolatedStorageFile isStore            = IsolatedStorageFile.GetUserStoreForApplication();
                    IsolatedStorageFileStream targetStream = isStore.OpenFile(finalfilepath, FileMode.Open, FileAccess.Read);

                    imageCanvas.Source = new BitmapImage(new Uri(targetStream.Name));

                    imageCanvas.Visibility   = Visibility.Visible;
                    ShutterButton.Visibility = Visibility.Collapsed;
                    ShutterButton.IsEnabled  = false;
                    ConfirmButton.Visibility = Visibility.Visible;
                    ConfirmButton.IsEnabled  = true;

                    targetStream.Dispose();
                });
            }
            finally
            {
                finalfilepath = fileName;
                // Close image stream
                e.ImageStream.Close();
            }
        }
示例#14
0
 /// <summary>
 /// Called when the <see cref="PhotoCamera.CaptureImageAvailable"/> event occurs.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="Microsoft.Devices.ContentReadyEventArgs"/> instance containing the event data.</param>
 private void OnPhotoCameraCaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
 {
     RaiseCaptureImageAvailable(new ContentReadyEventArgs(e.ImageStream));
 }
示例#15
0
 // Informs when full resolution picture has been taken, saves to local media library and isolated storage.
 void cam_CaptureImageAvailable(object sender, Microsoft.Devices.ContentReadyEventArgs e)
 {
 }