/// <summary> /// 由臉部樣本ID取得圖像 /// </summary> /// <param name="id"></param> /// <returns></returns> public JsonResult GetFaceByItID(string id) { try { _faceService = new FaceDP(Server.MapPath("~")); var face = _faceService.GetFaceById(id).ToBitmap(); //轉換影像成Stream var stream = new MemoryStream(); face.Save(stream, ImageFormat.Jpeg); var faceStream = new MemoryStream(); face.Save(faceStream, ImageFormat.Jpeg); //to base64 // Convert byte[] to Base64 String var imageBytes = stream.ToArray(); string base64String = Convert.ToBase64String(imageBytes); return(Json(base64String)); } catch (Exception ex) { return(this.Json(new { success = false, message = "取得失敗! \n" + ex.Message })); } }
private void _facesListBox_SelectedIndexChanged(object sender, EventArgs e) { var id = _facesListBox.SelectedItem.ToString(); _userFaceImageBox.Image = _faceService.GetFaceById(id); }