Beispiel #1
0
 /// <summary>
 /// Event Handler for BtnBrowseForPictureFile.Click event.
 /// Browse for Picture file and set pictureBoxPhoto Image and Tag(byte array).
 /// </summary>
 /// <param name="sender">Sender of event</param>
 /// <param name="e">Event arguments</param>
 private void BtnBrowseForPictureFile_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog ofd = new OpenFileDialog())
     {
         ofd.Multiselect = false;
         ofd.Title       = "Browse for a Picture File";
         // browse for the file
         if (ofd.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 // get image from file
                 Image img = Image.FromFile(ofd.FileName);
                 // resize image so that height=100
                 pictureBoxPhoto.Image = ImageFunctions.ResizeImage(img, (int)(100.0m * img.Width / img.Height), 100);
                 // set tag to byte array of image in bitmap format
                 pictureBoxPhoto.Tag = ImageFunctions.GetByteArrayFromBitMapImage(pictureBoxPhoto.Image);
             }
             catch (Exception ex)
             {
                 LogFunctions.LogException(ex);
                 _ = MessageBox.Show("A problem occurred while loading the photo from the file.",
                                     "Invalid Photo File",
                                     MessageBoxButtons.OK);
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Event Handler for btnTakePhotoWithCamera.Click event.
        /// Get Webcam Image. Set pictureBoxPhoto Image and Tag to bytearray of Image.
        /// </summary>
        /// <param name="sender">Sender of event</param>
        /// <param name="e">Event arguments</param>
        private void BtnTakePhotoWithCamera_Click(object sender, EventArgs e)
        {
            Bitmap webcamBitmap = ImageFunctions.GetBitmapFromWebcam();

            // if null, there was a problem getting webcamBitmap
            // if not null, set pictureBoxPhoto Image and Tag
            if (webcamBitmap != null)
            {
                pictureBoxPhoto.Image = webcamBitmap;
                pictureBoxPhoto.Tag   = ImageFunctions.GetByteArrayFromBitMapImage(webcamBitmap);
            }
        }