Esempio n. 1
0
 public EditorPageViewModel(ILogger <EditorPageViewModel> logger, IImageFilterService imageFilterService, INavigationService navigationService, IInOutService ioService)
 {
     this.logger             = logger;
     this.imageFilterService = imageFilterService;
     GaussFilterParams       = new GaussFilterParams()
     {
         Mid      = 0.2f,
         MidTop   = 0.2f,
         LeftMid  = 0.2f,
         RightMid = 0.2f,
         MidBot   = 0.2f
     };
     BinarizationFilterParams = new BinarizationFilterParams()
     {
         RedParameter        = 0.3f,
         GreenParameter      = 0.6f,
         BlueParameter       = 0.11f,
         PrecisionParameter  = 6,
         AdjustmentParameter = 0.15f
     };
     CurrentFilters = new ObservableCollection <FilterParamsBase>();
     InitializeCommands();
     NavigationService = navigationService;
     this.ioService    = ioService;
 }
Esempio n. 2
0
        private void InitializeCommands()
        {
            AddGaussFilterCommand = new RelayCommand(async x =>
            {
                var filter = GaussFilterParams.Clone() as GaussFilterParams;
                CurrentFilters.Add(filter);
                EditedImage.PhotoData.CurrentFilters.Add(filter);
                if (ServerModeEnabled)
                {
                    using (var client = new HttpClient())
                    {
                        client.DefaultRequestHeaders.Add("Accept", "application/json");
                        var transferObject = new GaussTransferModel()
                        {
                            ImageByteArray = ioService.BitmapSourceToByteArray(EditedImage.CurrentImage),
                            Parameters     = filter
                        };
                        var request     = new HttpRequestMessage(HttpMethod.Post, "https://localhost:44337/weatherforecast/GetGauss");
                        request.Content = new StringContent(JsonConvert.SerializeObject(transferObject), Encoding.UTF8, "application/json");
                        var response    = await client.SendAsync(request);

                        if (response.StatusCode == System.Net.HttpStatusCode.OK)
                        {
                            var jsonString           = await response.Content.ReadAsStringAsync();
                            var resultImg            = JsonConvert.DeserializeObject <GaussTransferModel>(jsonString);
                            EditedImage.CurrentImage = ioService.ByteArrayToBitmapImage(resultImg.ImageByteArray);
                        }
                    }
                }
                else
                {
                    EditedImage.CurrentImage = imageFilterService.ApplyFilter(EditedImage.CurrentImage, filter);
                }
            });

            AddBinarizationFilterCommand = new RelayCommand(async x =>
            {
                var filter = BinarizationFilterParams.Clone() as BinarizationFilterParams;
                CurrentFilters.Add(filter);
                EditedImage.PhotoData.CurrentFilters.Add(filter);

                if (ServerModeEnabled)
                {
                    using (var client = new HttpClient())
                    {
                        client.DefaultRequestHeaders.Add("Accept", "application/json");
                        var transferObject = new BinaryTransferModel()
                        {
                            ImageByteArray = ioService.BitmapSourceToByteArray(EditedImage.CurrentImage),
                            Parameters     = filter
                        };
                        var request     = new HttpRequestMessage(HttpMethod.Post, "https://localhost:44337/weatherforecast/GetBinarization");
                        request.Content = new StringContent(JsonConvert.SerializeObject(transferObject), Encoding.UTF8, "application/json");
                        var response    = await client.SendAsync(request);

                        if (response.StatusCode == System.Net.HttpStatusCode.OK)
                        {
                            var jsonString           = await response.Content.ReadAsStringAsync();
                            var resultImg            = JsonConvert.DeserializeObject <BinaryTransferModel>(jsonString);
                            EditedImage.CurrentImage = ioService.ByteArrayToBitmapImage(resultImg.ImageByteArray);
                        }
                    }
                }
                else
                {
                    EditedImage.CurrentImage = imageFilterService.ApplyFilter(EditedImage.CurrentImage, filter);
                }
            });

            SavePhotoCommand = new RelayCommand(x =>
            {
                ioService.ExportImage(editedImage);
                NavigationService.MoveToPage(Enums.PageEnum.galleryPage);
            });

            CancelPhotoCommand = new RelayCommand(x =>
            {
                NavigationService.MoveToPage(Enums.PageEnum.galleryPage);
            });
            RemoveSelectedFilter = new RelayCommand(x =>
            {
                if (SelectedFilter == null)
                {
                    return;
                }
                var filterToRemove = SelectedFilter;
                CurrentFilters.Remove(filterToRemove);
                EditedImage.PhotoData.CurrentFilters.Remove(filterToRemove);
                imageFilterService.ReApplyFilters(editedImage);
                SelectedFilter = CurrentFilters.FirstOrDefault();
            });
        }