Exemplo n.º 1
0
        public async Task TakePicture()
        {
            CameraCaptureUI captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;

            // captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200);

            StorageFile photoFile = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);


            if (photoFile != null)
            {
                IRandomAccessStreamWithContentType stream = await photoFile.OpenReadAsync();

                var buffer = new byte[stream.Size];

                await stream.ReadAsync(buffer.AsBuffer(), (uint)stream.Size, InputStreamOptions.None);

                var photo = new Photo {
                    Content = buffer, Description = "My photo"
                };

                await _PhotosService.AddAsync(photo);
            }
        }
        public async Task <IHttpActionResult> Post(int loadId)
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            var provider = new MultipartMemoryStreamProvider();
            await Request.Content.ReadAsMultipartAsync(provider);

            foreach (var file in provider.Contents)
            {
                var filename = file.Headers.ContentDisposition.FileName.Trim('\"');
                var buffer   = await file.ReadAsByteArrayAsync();

                var photo = new Photo {
                    Content = buffer
                };

                await _PhotosService.AddAsync(photo);
            }

            return(Ok());
        }