Пример #1
0
        public PicResponse SavePic(PicRequest picrequest)
        {
            //var aaa = "http://localhost:9143/api";
            var client  = new RestClient(serviceUrl);
            var request = new RestRequest("Client/SavePic", Method.POST);

            request.AddParameter("application/json", JsonConvert.SerializeObject(picrequest), ParameterType.RequestBody);
            var response = client.Execute(request);

            return(JsonConvert.DeserializeObject <PicResponse>(response.Content));
        }
Пример #2
0
        public PicResponse SavePic([FromBody] PicRequest picrequest)
        {
            try
            {
                string serverPath = @"C:\exampic\";

                if (!Directory.Exists(serverPath))
                {
                    Directory.CreateDirectory(serverPath);
                }

                var profilePicFileName = string.Format("{0}", picrequest.FileName);
                var path = Path.Combine(serverPath, profilePicFileName);
                System.IO.File.WriteAllBytes(path, picrequest.bytes);
                return(new PicResponse {
                    PicUrl = path
                });
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #3
0
        private void SavePic(BitmapSource bitmap)
        {
            TestingData.ProfilePhoto = new BitmapImage();

            JpegBitmapEncoder encoder = new JpegBitmapEncoder();

            encoder.Frames.Add(BitmapFrame.Create(bitmap));
            encoder.QualityLevel = 100;

            //HACK
            TestingData.SubjectCode = "11";

            var PICTURE_FILENAME = string.Format("{0}.jpg", TestingData.sheet._id);
            //var PICTURE_FILENAME = "";
            string serverPath = @"C:\PCTest\pic\";
            var    picPath    = System.IO.Path.Combine(serverPath, PICTURE_FILENAME);

            if (!Directory.Exists(serverPath))
            {
                Directory.CreateDirectory(serverPath);
            }

            using (var fstream = new System.IO.FileStream(picPath, FileMode.Create))
            {
                encoder.Save(fstream);
                fstream.Flush();
                fstream.Close();
                fstream.Dispose();

                webcam.Stop();
                _isCameraOn = false;
            }

            var profileBitmap = BitmapFromSource(bitmap);

            ProfilePhoto = profileBitmap;


            TestingData.ProfilePhoto = new BitmapImage();
            Uri uri = new Uri(picPath, UriKind.RelativeOrAbsolute);

            TestingData.ProfilePhoto.BeginInit();
            TestingData.ProfilePhoto.UriSource   = uri;
            TestingData.ProfilePhoto.CacheOption = BitmapCacheOption.OnLoad;
            TestingData.ProfilePhoto.EndInit();

            //save image to server
            byte[] bit = new byte[0];

            using (var stream = new System.IO.MemoryStream())
            {
                JpegBitmapEncoder encoder2 = new JpegBitmapEncoder();
                encoder2.Frames.Add(BitmapFrame.Create(bitmap));
                encoder2.QualityLevel = 100;
                encoder2.Save(stream);
                bit = stream.ToArray();

                OnsiteServices svc = new OnsiteServices();

                PicRequest picre = new PicRequest
                {
                    FileName = PICTURE_FILENAME,
                    bytes    = bit
                };
                svc.SavePic(picre);

                stream.Flush();
                stream.Close();
                stream.Dispose();
            }
        }