Пример #1
0
        private void Window_Drop(object sender, DragEventArgs e)
        {
            //get file draged to window
            string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
            if (fileList.Length == 1) //accept only one file
            {
                //display image file in input
                string file             = fileList[0];
                System.Drawing.Image im = null;
                try
                {
                    im = System.Drawing.Image.FromFile(file);
                }
                catch
                { }

                if (im != null) //if valid image
                {
                    //clear images from controls
                    picInput.Source  = null;
                    picOutput.Source = null;

                    //set images
                    currInputImage  = im;
                    currOutputImage = null;

                    //set current images
                    picInput.Source  = ImageEncoder.ToBitmapImage(im);    //set it as input image
                    picOutput.Source = new BitmapImage(noOutputImageUri); //set to no image picture
                }
                else //invalid image
                {
                    //clear images
                    picInput.Source  = null;
                    picOutput.Source = null;

                    //set images
                    currInputImage  = null;
                    currOutputImage = null;

                    //set current images
                    picInput.Source  = new BitmapImage(noInputImageUri);  //set to no image picture
                    picOutput.Source = new BitmapImage(noOutputImageUri); //set to no image picture
                }
            }
        }
Пример #2
0
        private void btnConvert_Click(object sender, RoutedEventArgs e)
        {
            if (currInputImage == null) //no image selected
            {
                MessageBox.Show("Select the image first!", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            this.Cursor = Cursors.Wait; //change cursor

            currOutputImage = null;     //clear output image

            client.Connect();           //connect to server

            //check if connection is active
            if (client.IsConnected == true)
            {
                //create xml message
                string message = CreateXMLMessage();
                if (message == string.Empty)
                {
                    return;
                }

                //send message to server and get server response
                string returnImageBase64    = client.SendMessageAndReceive(message);
                System.Drawing.Image imgRet = ImageEncoder.Base64ToImage(returnImageBase64);
                if (imgRet != null)
                {
                    picOutput.Source = ImageEncoder.ToBitmapImage(imgRet);
                    currOutputImage  = imgRet;
                }

                client.Disconnect();         //close server connection

                this.Cursor = Cursors.Arrow; //change cursor
            }
            else
            {
                this.Cursor = Cursors.Arrow; //change cursor

                //alert user
                MessageBox.Show("Unable to connect to image server!", "Erorr", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }