예제 #1
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;
 }