コード例 #1
0
        private void PHandler_OnFinished(object sender, PhotoHandlerEventArgs e)
        {
            if (e.Exception == null)
            {
                MemoryStream      ms            = new MemoryStream();
                ImageCodecInfo    jpgEncoder    = BitmapExtensions.GetEncoderInfo(ImageFormat.Jpeg);
                EncoderParameters encoderParams = new EncoderParameters(1);
                EncoderParameter  encoderParam  = new EncoderParameter(Encoder.Quality, 100L);
                encoderParams.Param[0] = encoderParam;
                e.Image.Save(ms, jpgEncoder, encoderParams);
                ms.Position = 0;
                BinaryReader br           = new BinaryReader(ms);
                byte[]       bytes        = br.ReadBytes((int)ms.Length);
                string       base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
                HandledImage.ImageUrl = "data:image/jpeg;base64," + base64String;
            }
            else
            {
                Logger.WriteLog(nameof(PHandler_OnFinished), e.Exception);
                HandledImage.ImageUrl = "Content/ui/faceNotFound.jpg";
                HandledMessage.Text   = e.Exception.Message;
            }

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
        }
コード例 #2
0
        private void selectBtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.Image = BitmapExtensions.LoadImageFitSize(ofd.FileName);
                phandler.Detect(ofd.FileName);
            }
        }
コード例 #3
0
ファイル: PhotoHandler.cs プロジェクト: lyhyl/HowAreYouToday
 public void Detect(string filename, EventHandler <PhotoHandlerEventArgs> callback)
 {
     lock (detectorLock)
     {
         fname = System.IO.Path.GetFileNameWithoutExtension(filename);
         Logger.WriteLog($"Detect {fname}");
         OnFinished     = callback;
         imageToProcess = BitmapExtensions.LoadImageFitSize(filename);
         detectors.First().Process(imageToProcess);
     }
 }
コード例 #4
0
ファイル: PhotoHandler.cs プロジェクト: lyhyl/HowAreYouToday
 public void Detect(string filename)
 {
     imageToProcess = BitmapExtensions.LoadImageFitSize(filename);
     detecters.First().Process(imageToProcess);
 }