private async void HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            CameraCaptureUI captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200);
            StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            AddAttachement(photo);
        }
Пример #2
0
        protected async System.Threading.Tasks.Task TakeSnapshotAsync <T>(T list, string fieldName) where T : ObservableCollection <ImageCapture>
        {
            try
            {
                CameraCaptureUI ccui        = new CameraCaptureUI();
                var             storagefile = await ccui.CaptureFileAsync(CameraCaptureUIMode.Photo);

                if (storagefile != null)
                {
                    var ms = await RenderDataStampOnSnap.RenderStaticTextToBitmap(storagefile);

                    var    msrandom = new MemoryRandomAccessStream(ms);
                    Byte[] bytes    = new Byte[ms.Length];
                    await ms.ReadAsync(bytes, 0, (int)ms.Length);

                    // StorageFile file = await KnownFolders.PicturesLibrary.CreateFileAsync("Image.png", Windows.Storage.CreationCollisionOption.GenerateUniqueName);

                    StorageFile file = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(DateTime.Now.Ticks.ToString() + storagefile.Name, CreationCollisionOption.ReplaceExisting);

                    using (var strm = await file.OpenStreamForWriteAsync())
                    {
                        await strm.WriteAsync(bytes, 0, bytes.Length);

                        strm.Flush();
                    }

                    var ic = new ImageCapture
                    {
                        ImagePath        = file.Path,
                        ImageBinary      = Convert.ToBase64String(bytes),
                        CaseServiceRecId = ((BaseModel)this.Model).VehicleInsRecID,
                        FileName         = string.Format("{0}_{1}", fieldName, list.Count + 1)
                    };
                    list.Add(ic);

                    var imageTable = await SqliteHelper.Storage.LoadTableAsync <ImageCapture>();

                    var dbIC = imageTable.SingleOrDefault(x => x.CaseServiceRecId == ic.CaseServiceRecId && x.FileName == string.Format("{0}_{1}", fieldName, list.Count + 1));
                    if (dbIC == null)
                    {
                        await SqliteHelper.Storage.InsertSingleRecordAsync <ImageCapture>(ic);
                    }
                    else
                    {
                        dbIC.ImagePath   = ic.ImagePath;
                        dbIC.ImageBinary = ic.ImageBinary;
                        await SqliteHelper.Storage.UpdateSingleRecordAsync <ImageCapture>(dbIC);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            CameraCaptureUI capture = new CameraCaptureUI();

            capture.PhotoSettings.Format             = CameraCaptureUIPhotoFormat.Jpeg;
            capture.PhotoSettings.CroppedAspectRatio = new Size(3, 5);
            capture.PhotoSettings.MaxResolution      = CameraCaptureUIMaxPhotoResolution.HighestAvailable;
            storeFile = await capture.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (storeFile != null)
            {
                BitmapImage bimage = new BitmapImage();
                stream = await storeFile.OpenAsync(FileAccessMode.Read);;
                await bimage.SetSourceAsync(stream);

                captureImage.Source = bimage;



                DateTime dt    = DateTime.Now;
                string   dtstr = dt.ToString("ddMyyyy");

                string filename = "imagerecordedat" + dtstr;


                try
                {
                    //FileSavePicker save = new FileSavePicker();
                    //save.FileTypeChoices.Add("Image", new List<string>() { ".jpeg" });
                    //save.DefaultFileExtension = ".jpeg";
                    //save.SuggestedFileName = "Image" + filename;
                    //save.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                    //save.SuggestedSaveFile = storeFile;
                    //var s = await save.PickSaveFileAsync();

                    using (var reader = new DataReader(stream.GetInputStreamAt(0)))
                    {
                        await reader.LoadAsync((uint)stream.Size);

                        byte[] buffer = new byte[(int)stream.Size];
                        reader.ReadBytes(buffer);
                        await FileIO.WriteBytesAsync(storeFile, buffer);
                        await Upload(storeFile, buffer);
                    }
                }
                catch (Exception ex) {
                    string BadResult = "somethings gone wrong" + ex;
                    Windows.UI.Popups.MessageDialog dlg = new
                                                          Windows.UI.Popups.MessageDialog(BadResult);

                    await dlg.ShowAsync();
                }
                this.Frame.Navigate(typeof(BlankPage4));
            }
        }
Пример #4
0
 private void slikica_Click(object sender, RoutedEventArgs e)
 {
     var capture = new CameraCaptureUI
     {
         PhotoSettings =
         {
             Format = CameraCaptureUIPhotoFormat.Jpeg
         }
     };
     var file = capture.CaptureFileAsync(CameraCaptureUIMode.Photo);
 }
Пример #5
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            CameraCaptureUI cam  = new CameraCaptureUI();
            StorageFile     file = await cam.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (file != null)
            {
                BitmapImage image = new BitmapImage(new Uri(file.Path));
                image1.Source = image;
            }
        }
        public async Task <StorageFile> TakePicture()
        {
            CameraCaptureUI captureUi = new CameraCaptureUI();

            captureUi.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            captureUi.PhotoSettings.CroppedSizeInPixels = new Size(100.0, 70.0);

            StorageFile photo = await captureUi.CaptureFileAsync(CameraCaptureUIMode.Photo);

            return(photo);
        }
        private async void InitCamera()
        {
            var camera = new CameraCaptureUI();

            var photo = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (photo != null)
            {
                img.Source = new BitmapImage(new Uri(photo.Path));
            }
        }
Пример #8
0
        private async void OnCapturePhoto(object sender, TappedRoutedEventArgs e)
        {
            var camera = new CameraCaptureUI();
            var file   = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (file != null)
            {
                _photo = file;
                DataTransferManager.ShowShareUI();
            }
        }
Пример #9
0
        public static async Task <StorageFile> FromCamera()
        {
            CameraCaptureUI captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.AllowCropping = false;
            captureUI.PhotoSettings.Format        = CameraCaptureUIPhotoFormat.Jpeg;

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

            return(photoFile);
        }
Пример #10
0
        private async void TakePhoto(object sender, RoutedEventArgs e)
        {
            var camera = new CameraCaptureUI();

            camera.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            var file = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (file != null)
            {
                await AddImageDataFromFile(file);
            }
        }
Пример #11
0
        public async Task <ImageSource> TakePhotoAsync()
        {
            CameraCaptureUI captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;

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

            var stream = await photo.OpenStreamForReadAsync();

            return(ImageSource.FromStream(() => stream));
        }
Пример #12
0
        private async void abb_mail_Click(object sender, RoutedEventArgs e)
        {
            CameraCaptureUI dialog = new CameraCaptureUI();

            Size aspectRatio = new Size(16, 9);

            dialog.PhotoSettings.CroppedAspectRatio = aspectRatio;

            StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Video);

            sendMail(file);
        }
Пример #13
0
        private async void VideoOrPhoto(object sender, TappedRoutedEventArgs e)
        {
            var camera = new CameraCaptureUI();

            camera.PhotoSettings.Format        = CameraCaptureUIPhotoFormat.Jpeg;
            camera.PhotoSettings.AllowCropping = true;
            camera.VideoSettings.Format        = CameraCaptureUIVideoFormat.Mp4;
            camera.VideoSettings.AllowTrimming = true;
            var file = await camera.CaptureFileAsync(CameraCaptureUIMode.PhotoOrVideo);

            Debug.WriteLine($"file={file.Name} ({file.ContentType})");
        }
Пример #14
0
        private async void CameraButton_Click(object sender, RoutedEventArgs e)
        {
            CameraCaptureUI captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.Large3M;
            var photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (photo != null)
            {
                NavigateToAnalisys(photo);
            }
        }
        public async Task LaunchExtensionAsync(AppExtension appExtension)
        {
            // Il y a 2 types de packages, le bon et le mauvais
            // le bon, il est bon alors que le mauvais il est mauvais.
            if (false == appExtension.Package.Status.VerifyIsOK())
            {
                return;
            }

            // création d'une connexion
            var connection = new AppServiceConnection
            {
                AppServiceName = "com.infinitesquare.UWPWhatsNewExtension",

                // ciblage de l'extension
                PackageFamilyName = appExtension.Package.Id.FamilyName
            };

            var cameraCaptureUI = new CameraCaptureUI {
                PhotoSettings = { CroppedAspectRatio = new Size(1, 1), Format = CameraCaptureUIPhotoFormat.Jpeg }
            };
            var file = await cameraCaptureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (file == null)
            {
                return;
            }

            var token = SharedStorageAccessManager.AddFile(file);

            // ouverture de la connexion
            var result = await connection.OpenAsync();

            if (result != AppServiceConnectionStatus.Success)
            {
                return;
            }

            var inputs = new ValueSet {
                { "targetFileToken", token }
            };

            // send input and receive output in a variable
            var response = await connection.SendMessageAsync(inputs);

            var outputFileToken = response.Message["outputFileToken"].ToString();

            var outputFile = await SharedStorageAccessManager.RedeemTokenForFileAsync(outputFileToken);

            var copied = await outputFile.CopyAsync(ApplicationData.Current.TemporaryFolder, outputFile.Name);

            OutputImage = new BitmapImage(new Uri(copied.Path));
        }
Пример #16
0
        static async Task <FileInfo> DoTakePhoto(MediaCaptureSettings settings)
        {
            var capture = new CameraCaptureUI();

            capture.PhotoSettings.Format        = CameraCaptureUIPhotoFormat.Jpeg;
            capture.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.HighestAvailable;
            capture.PhotoSettings.AllowCropping = settings.AllowEditing;

            var result = await capture.CaptureFileAsync(CameraCaptureUIMode.Photo);

            return(await result.SaveToTempFile());
        }
Пример #17
0
        public async void Camera()
        {
            // initiate camera app
            CameraCaptureUI cam = new CameraCaptureUI();

            cam.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            //cam.PhotoSettings.CroppedAspectRatio = new Size(200, 200);
            StorageFile imageFile = await cam.CaptureFileAsync(CameraCaptureUIMode.Photo);

            //  img.Source = new BitmapImage(new Uri(imageFile.Path));
            // locationTxt.Text = imageFile.Path;
        }
Пример #18
0
        private async void AddImage_ClickAsync(object sender, RoutedEventArgs e)
        {
            CameraCaptureUI captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200);
            Photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            this.pictureButton.Visibility           = Visibility.Visible;
            this.ViewModel.SelectedBeleg.BelegImage = ReadFile(Photo);
            this.Frame.Navigate(typeof(PhotoPage), Photo);
        }
Пример #19
0
        private async void CapturePhoto_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                NotifyUser("Capture Starting...", NotifyType.StatusMessage);
                var dialog = new CameraCaptureUI();
                dialog.PhotoSettings.MaxResolution = _listedSize[cmbSize.SelectedIndex];
                dialog.PhotoSettings.Format        = CameraCaptureUIPhotoFormat.Jpeg;
                dialog.PhotoSettings.AllowCropping = false;

                if (tAllotCut.IsChecked.Value)
                {
                    dialog.PhotoSettings.AllowCropping      = true;
                    dialog.PhotoSettings.CroppedAspectRatio = _listedRatio[cmbRatio.SelectedIndex];
                }
                else
                {
                    dialog.PhotoSettings.AllowCropping = false;
                }

                //dialog.PhotoSettings.CroppedAspectRatio = _listedRatio[cmbRatio.SelectedIndex];

                StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);

                if (file != null)
                {
                    BitmapImage bitmapImage = new BitmapImage();
                    using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read))
                    {
                        bitmapImage.SetSource(fileStream);
                    }
                    CapturedPhoto.Source = bitmapImage;

                    appSettings[photoKey] = file.Path;

                    NotifyUser("Photo is saved at:" + file.Path, NotifyType.StatusMessage);

                    var StreamRandom = await file.OpenAsync(FileAccessMode.Read);

                    pushToServer(StreamRandom);
                    StreamRandom.Dispose();
                }
                else
                {
                    NotifyUser("No photo captured.", NotifyType.StatusMessage);
                }
            }
            catch (Exception ex)
            {
                NotifyUser(ex.Message, NotifyType.ErrorMessage);
            }
        }
Пример #20
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            var camera = new CameraCaptureUI();
            var file   = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo);

            using (var s = await file.OpenReadAsync())
            {
                var bitmap = new BitmapImage();
                await bitmap.SetSourceAsync(s);

                picture.Source = bitmap;
            }
        }
Пример #21
0
        private async void OnCaptureVideo(object sender, TappedRoutedEventArgs e)
        {
            var camera = new CameraCaptureUI();

            camera.VideoSettings.Format = CameraCaptureUIVideoFormat.Wmv;
            var file = await camera.CaptureFileAsync(CameraCaptureUIMode.Video);

            if (file != null)
            {
                _video = file;
                DataTransferManager.ShowShareUI();
            }
        }
Пример #22
0
        public async Task <string> Screen()
        {
            try {
                CameraCaptureUI camera = new CameraCaptureUI();
                camera.PhotoSettings.Format        = CameraCaptureUIPhotoFormat.Jpeg;
                camera.PhotoSettings.AllowCropping = false;
                StorageFile photo = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo);

                return(photo.Path);
            } catch {
                throw new Exception("Ошибка камеры");
            }
        }
Пример #23
0
        /// <summary>
        /// 打开相机拍照
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void FromCamera_Tapped(object sender, TappedRoutedEventArgs e)
        {
            CameraCaptureUI captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200);
            StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (ImageSelected != null && photo != null)
            {
                ImageSelected(photo);
            }
        }
Пример #24
0
        public async void CaptureButton_Click(object sender,
                                              RoutedEventArgs e)
        {
            CheckAndClearShareOperation();
            var camera = new CameraCaptureUI();
            var result = await camera.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (result != null)
            {
                await LoadBitmap(await result.OpenAsync(
                                     FileAccessMode.Read));
            }
        }
Пример #25
0
        private async void TakePictureCommand(object parameter)
        {
            var cameraCapture = new CameraCaptureUI();

            cameraCapture.PhotoSettings.CroppedAspectRatio = new Size(4, 3);

            var file = await cameraCapture.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (file != null)
            {
                FilePickerController.SavePicture(file);
            }
        }
Пример #26
0
        public static async Task <byte[]> TakePicture()
        {
            CameraCaptureUI captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.Format        = CameraCaptureUIPhotoFormat.Jpeg;
            captureUI.PhotoSettings.AllowCropping = true;

            var storageFile = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            var fileBytes = await ReadFileBytes(storageFile);

            return(fileBytes);
        }
Пример #27
0
 private async void Capture_Photo(object sender, RoutedEventArgs e)
 {
     CameraCaptureUI captureUI = new CameraCaptureUI();
     captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
     captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200);
     file = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
     if (file == null)
     {
         // User cancelled photo capture
         return;
     }
     HttpUploadFile(UploadUrl, "myFile", "image/png");
 }
Пример #28
0
        /// <summary>
        /// Take a video with specified options
        /// </summary>
        public async Task <MediaFile> TakeVideoAsync(StoreVideoOptions options)
        {
            await _InitializeTask;

            if (_Devices.Count == 0)
            {
                throw new NotSupportedException();
            }

            options.VerifyOptions();

            var capture = new CameraCaptureUI();

            capture.VideoSettings.MaxResolution = GetResolutionFromQuality(options.Quality);
            capture.VideoSettings.AllowTrimming = options?.AllowCropping ?? true;

            if (capture.VideoSettings.AllowTrimming)
            {
                capture.VideoSettings.MaxDurationInSeconds = (float)options.DesiredLength.TotalSeconds;
            }

            capture.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4;

            var result = await capture.CaptureFileAsync(CameraCaptureUIMode.Video);

            if (result == null)
            {
                return(null);
            }

            if (!(options?.SaveToAlbum ?? false))
            {
                return(new MediaFile(result.Path, () => result.OpenStreamForReadAsync().Result, null));
            }

            string aPath = null;

            try
            {
                var fileNameNoEx = Path.GetFileNameWithoutExtension(result.Path);
                var copy         = await result.CopyAsync(KnownFolders.VideosLibrary, fileNameNoEx + result.FileType, NameCollisionOption.GenerateUniqueName);

                aPath = copy.Path;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("unable to save to album:" + ex);
            }

            return(new MediaFile(result.Path, () => result.OpenStreamForReadAsync().Result, aPath));
        }
Пример #29
0
        async private void btnCamera_Click(object sender, RoutedEventArgs e)
        {
            var ui = new CameraCaptureUI();

            ui.PhotoSettings.CroppedAspectRatio = new Size(16, 9);           // 4,3 ya da benzer boyutları ekleyebilirisiniz
            var file = await ui.CaptureFileAsync(CameraCaptureUIMode.Photo); // Photo ,Video ya da PhotoVideo

            if (file != null)
            {
                bitmap = new BitmapImage();
                bitmap.SetSource(await file.OpenAsync(FileAccessMode.Read));
                imgVideo.Source = bitmap;
            }
        }
Пример #30
0
        private async void Capture_Photo(object sender, RoutedEventArgs e)
        {
            CameraCaptureUI captureUI = new CameraCaptureUI();

            captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200);
            StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

            if (photo == null)
            {
                // User cancelled photo capture
                return;
            }
        }
Пример #31
0
    /// <summary>
    /// Take a photo async with specified options
    /// </summary>
    /// <param name="options">Camera Media Options</param>
    /// <returns>Media file of photo or null if canceled</returns>
    public async Task<MediaFile> TakePhotoAsync(StoreCameraMediaOptions options)
    {
      if (!IsCameraAvailable)
        throw new NotSupportedException();

      options.VerifyOptions();

      var capture = new CameraCaptureUI();
      var result = await capture.CaptureFileAsync(CameraCaptureUIMode.Photo, options);
      if (result == null)
        return null;

      StorageFolder folder = ApplicationData.Current.LocalFolder;

      string path = options.GetFilePath(folder.Path);
      var directoryFull = Path.GetDirectoryName(path);
      var newFolder = directoryFull.Replace(folder.Path, string.Empty);
      if (!string.IsNullOrWhiteSpace(newFolder))
        await folder.CreateFolderAsync(newFolder, CreationCollisionOption.OpenIfExists);

      folder = await StorageFolder.GetFolderFromPathAsync(directoryFull);

      string filename = Path.GetFileName(path);

      var file = await result.CopyAsync(folder, filename, NameCollisionOption.GenerateUniqueName).AsTask();
      return new MediaFile(file.Path, () => file.OpenStreamForReadAsync().Result);
    }
        /// <summary>
        /// Take a photo async with specified options
        /// </summary>
        /// <param name="options">Camera Media Options</param>
        /// <returns>Media file of photo or null if canceled</returns>
        public async Task<MediaFile> TakePhotoAsync(StoreCameraMediaOptions options)
        {
            if (!initialized)
                await Initialize();

            if (!IsCameraAvailable)
                throw new NotSupportedException();

            options.VerifyOptions();

            var capture = new CameraCaptureUI();
            var result = await capture.CaptureFileAsync(CameraCaptureUIMode.Photo, options);
            if (result == null)
                return null;
            
            StorageFolder folder = ApplicationData.Current.LocalFolder;

            string path = options.GetFilePath(folder.Path);
            var directoryFull = Path.GetDirectoryName(path);
            var newFolder = directoryFull.Replace(folder.Path, string.Empty);
            if (!string.IsNullOrWhiteSpace(newFolder))
                await folder.CreateFolderAsync(newFolder, CreationCollisionOption.OpenIfExists);

            folder = await StorageFolder.GetFolderFromPathAsync(directoryFull);

            string filename = Path.GetFileName(path);
            string aPath = null;
            if (options?.SaveToAlbum ?? false)
            {
                try
                {
                    string fileNameNoEx = Path.GetFileNameWithoutExtension(path);
                    var copy = await result.CopyAsync(KnownFolders.PicturesLibrary, fileNameNoEx + result.FileType, NameCollisionOption.GenerateUniqueName);
                    aPath = copy.Path;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("unable to save to album:" + ex);
                }
            }

            var file = await result.CopyAsync(folder, filename, NameCollisionOption.GenerateUniqueName).AsTask();
            return new MediaFile(file.Path, () => file.OpenStreamForReadAsync().Result, albumPath: aPath);
        }