Ejemplo n.º 1
0
        private async Task SaveAsync()
        {
            var stream = new InMemoryRandomAccessStream();
            await ImageCropper.SaveAsync(stream, BitmapFileFormat.Png);

            App.ViewModel.IsLoading = true;
            var dispatcherQueue = Windows.System.DispatcherQueue.GetForCurrentThread();
            var data            = await App.Repository.User.UploadAvatarAsync(stream, async res =>
            {
                await dispatcherQueue.EnqueueAsync(() =>
                {
                    App.ViewModel.IsLoading = false;
                    _ = new MessageDialog(res.Message ?? Constants.GetString("unknow_error")).ShowAsync();
                });
            });

            stream.Dispose();
            await dispatcherQueue.EnqueueAsync(() =>
            {
                App.ViewModel.IsLoading = false;
                if (data == null)
                {
                    return;
                }
                App.ViewModel.User = data;
                Frame.GoBack();
            });
        }
Ejemplo n.º 2
0
        private async void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            var picker = new FileSavePicker
            {
                SuggestedStartLocation = PickerLocationId.PicturesLibrary,
                SuggestedFileName      = "Crop_Image"
            };

            picker.FileTypeChoices.Add("Png Picture", new List <string> {
                ".png", ".jpg"
            });
            var file = await picker.PickSaveFileAsync();

            if (file != null)
            {
                if (file.Name.Contains(".png"))
                {
                    await ImageCropper.SaveAsync(file, BitmapFileFormat.Png);
                }
                else
                {
                    await ImageCropper.SaveAsync(file, BitmapFileFormat.Jpeg);
                }
            }
        }
Ejemplo n.º 3
0
        //private double AspectRatio = 1.91d;
        //private void ComboAspectRatioSelectionChanged(object sender, SelectionChangedEventArgs e)
        //{
        //    try
        //    {
        //        if(ComboAspectRatio.SelectedIndex != -1)
        //        {
        //            switch(ComboAspectRatio.SelectedIndex)
        //            {
        //                case 0:
        //                    AspectRatio = 1.91d;
        //                    ImageCropper.AspectRatio = AspectRatio;
        //                    break;

        //                case 1:
        //                    AspectRatio = 1d;
        //                    ImageCropper.AspectRatio = AspectRatio;
        //                    break;

        //                case 2:
        //                    AspectRatio = 0.8d;
        //                    ImageCropper.AspectRatio = AspectRatio;
        //                    break;

        //            }
        //        }
        //    }
        //    catch { }
        //}

        private async void CropButtonClick(object sender, RoutedEventArgs e)
        {
            try
            {
                Helper.CreateCachedFolder();
                Helper.CreateCachedFolder();
                Helper.CreateCachedFolder();
                if (IsVideo)
                {
                    using (var fileStream = await ThumbnailFile.OpenAsync(FileAccessMode.ReadWrite, StorageOpenOptions.None))
                        await ImageCropper.SaveAsync(fileStream, BitmapFileFormat.Jpeg);
                    ThumbnailFile = await new PhotoHelper().SaveToImage(ThumbnailFile, false);
                    var decoder = await BitmapDecoder.CreateAsync(await ThumbnailFile.OpenReadAsync());

                    VideoBitmapDecoder         = decoder;
                    CurrentCroppedRectForVideo = ImageCropper.CurrentCroppedRect;
                    ShowImagePreview(ThumbnailFile);
                    UploadButton.IsEnabled = true;
                }
                else
                {
                    var cacheFolder = await SessionHelper.LocalFolder.GetFolderAsync("Cache");

                    var file = await cacheFolder.CreateFileAsync(15.GenerateRandomStringStatic() + ".jpg");

                    //await ImageCropper.CroppedImage.SaveAsync(file);
                    using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite, StorageOpenOptions.None))
                        await ImageCropper.SaveAsync(fileStream, BitmapFileFormat.Jpeg);
                    FileToUpload = await new PhotoHelper().SaveToImage(file, false, false);

                    //CropGrid.Visibility = Visibility.Collapsed;
                    ShowImagePreview(FileToUpload);
                    UploadButton.IsEnabled = true;
                }



                //using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite, StorageOpenOptions.None))
                //    await ImageCropper.SaveAsync(fileStream, BitmapFileFormat.Jpeg);
                //ThumbnailFile = await new PhotoHelper().SaveToImage(file, false);

                ////CropGrid.Visibility = Visibility.Collapsed;
                //ShowImagePreview(ThumbnailFile);
                //var converter = new VideoConverter();
                //var decoder = await BitmapDecoder.CreateAsync(await ThumbnailFile.OpenReadAsync());

                //var converted = await converter.ConvertFiles(new List<StorageFile> { FileToUpload }, false, new Size(decoder.PixelWidth, decoder.PixelHeight));
            }
            catch (Exception ex)
            {
                ex.PrintException("CropButtonClick");
            }
        }
Ejemplo n.º 4
0
        private async void OkImageButtonClick(object sender, RoutedEventArgs e)
        {
            try
            {
                ShowLoading();
                var cacheFolder = await SessionHelper.LocalFolder.GetFolderAsync("Cache");

                var file = await cacheFolder.CreateFileAsync(15.GenerateRandomStringStatic() + ".jpg");

                using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite, StorageOpenOptions.None))
                    await ImageCropper.SaveAsync(fileStream, UI.Controls.BitmapFileFormat.Jpeg);
                var fileToUpload = await new PhotoHelper().SaveToImage(file);
                Uploader.UploadSinglePhoto(fileToUpload);
            }
            catch { }
        }
Ejemplo n.º 5
0
        private async void CropButtonClick(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!CanCrop)
                {
                    Helper.ShowNotify("Please wait a few more seconds....");
                    return;
                }
                Helper.CreateCachedFolder();
                Helper.CreateCachedFolder();
                Helper.CreateCachedFolder();
                if (IsVideo)
                {
                    using (var fileStream = await ThumbnailFile.OpenAsync(FileAccessMode.ReadWrite, StorageOpenOptions.None))
                        await ImageCropper.SaveAsync(fileStream, BitmapFileFormat.Jpeg);
                    ThumbnailFile = await new PhotoHelper().SaveToImage(ThumbnailFile, false);
                    var decoder = await BitmapDecoder.CreateAsync(await ThumbnailFile.OpenReadAsync());

                    BitmapDecoder = decoder;
                    CurrentCroppedRectForVideo = ImageCropper.CurrentCroppedRect;
                    ShowImagePreview(ThumbnailFile);
                }
                else
                {
                    var cacheFolder = await SessionHelper.LocalFolder.GetFolderAsync("Cache");

                    var file = await cacheFolder.CreateFileAsync(15.GenerateRandomStringStatic() + ".jpg");

                    //await ImageCropper.CroppedImage.SaveAsync(file);
                    using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite, StorageOpenOptions.None))
                        await ImageCropper.SaveAsync(fileStream, BitmapFileFormat.Jpeg);
                    FileToUpload = await new PhotoHelper().SaveToImage(file, false, false);

                    var decoder = await BitmapDecoder.CreateAsync(await FileToUpload.OpenReadAsync());

                    BitmapDecoder = decoder;
                    //CropGrid.Visibility = Visibility.Collapsed;
                    ShowImagePreview(FileToUpload);
                }
                Editing = false;
            }
            catch (Exception ex)
            {
                ex.PrintException("CropButtonClick");
            }
        }
Ejemplo n.º 6
0
        private async Task SaveCroppedImage()
        {
            var savePicker = new FileSavePicker
            {
                SuggestedStartLocation = PickerLocationId.PicturesLibrary,
                SuggestedFileName      = "Cropped_Image",
                FileTypeChoices        =
                {
                    { "PNG Picture",  new List <string> {
                          ".png"
                      } },
                    { "JPEG Picture", new List <string> {
                          ".jpg"
                      } }
                }
            };
            var imageFile = await savePicker.PickSaveFileAsync();

            if (imageFile != null)
            {
                BitmapFileFormat bitmapFileFormat;
                switch (imageFile.FileType.ToLower())
                {
                case ".png":
                    bitmapFileFormat = BitmapFileFormat.Png;
                    break;

                case ".jpg":
                    bitmapFileFormat = BitmapFileFormat.Jpeg;
                    break;

                default:
                    bitmapFileFormat = BitmapFileFormat.Png;
                    break;
                }

                using (var fileStream = await imageFile.OpenAsync(FileAccessMode.ReadWrite, StorageOpenOptions.None))
                {
                    await _imageCropper.SaveAsync(fileStream, bitmapFileFormat);
                }
            }
        }
Ejemplo n.º 7
0
        private async void CropButtonClick(object sender, RoutedEventArgs e)
        {
            try
            {
                Helper.CreateCachedFolder();
                Helper.CreateCachedFolder();
                Helper.CreateCachedFolder();
                var cacheFolder = await SessionHelper.LocalFolder.GetFolderAsync("Cache");

                var file = await cacheFolder.CreateFileAsync(15.GenerateRandomStringStatic() + ".jpg");

                using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite, StorageOpenOptions.None))
                    await ImageCropper.SaveAsync(fileStream, BitmapFileFormat.Jpeg);
                FileToUpload = await new PhotoHelper().SaveToImage(file, false);

                ShowImagePreview(FileToUpload);
                UploadButton.IsEnabled = true;
            }
            catch (Exception ex)
            {
                ex.PrintException("CropButtonClick");
            }
        }