public JsonResult AddPersonImage(string userName, string gender, string base64Image) { try { _faceService = new FaceDP(Server.MapPath("~")); // Convert Base64 String to byte[] byte[] imageBytes = Convert.FromBase64String(base64Image); MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length); // Convert byte[] to Image ms.Write(imageBytes, 0, imageBytes.Length); var faceImage = new Image <Bgr, byte>(new Bitmap(ms)); _faceService.SaveCropFace(userName, gender, faceImage.ToBitmap()); return(this.Json(new { success = true, message = string.Empty })); } catch (Exception ex) { return(this.Json(new { success = false, message = userName + gender + "新增失敗! \n" + ex.Message + "\n" + base64Image })); } }
private void _saveFaceButton_Click(object sender, EventArgs e) { MessageBox.Show(_faceService.SaveCropFace(_usernameTextBox.Text)); RefreshControl(); }