Exemplo n.º 1
0
        public MainWindow()
        {
            ip = "localhost";
            InitializeComponent();
            buttonImageSelect.IsEnabled = true;
            labelControl = new ProgressChecker();
            labelProgress.DataContext = labelControl;
            labelControl.Progress     = "prgress precent";
            imageControl             = new ImageChecker();
            boxImageShow.DataContext = imageControl;
            NetTcpBinding binding = new NetTcpBinding(SecurityMode.None, false);

            binding.MaxBufferSize          = int.MaxValue;
            binding.MaxReceivedMessageSize = int.MaxValue;
            factory = new ChannelFactory <IContract>(binding, new EndpointAddress($"net.tcp://{ip}:12345/srv"));
            client  = factory.CreateChannel();

            try
            {
                string[] filters = client.GetFilters();
                foreach (var filter in filters)
                {
                    comboBoxFilter.Items.Add(filter);
                }
                if (filters.Length < 1)
                {
                    throw new Exception("No Filters found");
                }
                comboBoxFilter.SelectedItem = comboBoxFilter.Items[0];
                buttonImageSelect.IsEnabled = true;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Exemplo n.º 2
0
 private void ParallelImageFilter(IContract client, byte[] inputImage, string filter, string parametrs, ImageChecker control, CancellationToken cancellation)
 {
     try
     {
         string[] filterParams    = { filter, parametrs };
         byte[]   imgBytesRecived = client.ApplyExtendedFilter(filterParams, inputImage);
         imageToSave = imgBytesRecived;
         isDone      = true;
         App.Current.Dispatcher.Invoke(() =>
         {
             Bitmap imageTemp;
             using (MemoryStream memoryStream = new MemoryStream(imageToSave))
             {
                 imageTemp = (Bitmap)Bitmap.FromStream(memoryStream);
             }
             if (imageSource != null)
             {
                 imageSource.Dispose();
             }
             imageSource = (Bitmap)imageTemp.Clone();
             BitmapSource bitmapImage = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(imageTemp.GetHbitmap(), IntPtr.Zero,
                                                                                                     Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(imageTemp.Width, imageTemp.Height));
             if (imageToSave != null)
             {
                 imageControl.Img = bitmapImage;
             }
         });
     }
     catch (Exception e)
     {
         if (cancellation.IsCancellationRequested)
         {
             return;
         }
         MessageBox.Show("Error in parallelFilterClient\n" + e.Message);
     }
     return;
 }