Beispiel #1
0
 public void Activate(object parameter)
 {
     if (parameter is PhotoViewModel)
     {
         EditedImage = parameter as PhotoViewModel;
         foreach (var filter in EditedImage.PhotoData.CurrentFilters)
         {
             CurrentFilters.Add(filter);
         }
     }
 }
Beispiel #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();
            });
        }