/// <summary> /// Create XML message for server /// </summary> /// <returns>Returns XML message as string</returns> private string CreateXMLMessage() { string result = string.Empty; //encode image to base 64 System.Drawing.Image img = currInputImage; string img64 = ImageEncoder.ImageToBase64(img, System.Drawing.Imaging.ImageFormat.Jpeg); //create message string grayscaleChecked = "0"; if (chkGrayscale.IsChecked == true) { grayscaleChecked = "1"; } string flipChecked = "0"; if (chkFlip.IsChecked == true) { flipChecked = "1"; } string rotateChecked = "0"; if (chkRotate.IsChecked == true) { if (rboRotate90.IsChecked == true) { rotateChecked = "90"; } if (rboRotate180.IsChecked == true) { rotateChecked = "180"; } if (rboRotate270.IsChecked == true) { rotateChecked = "270"; } } //create xml message result = XmlCreator.MakeXMLMessage(grayscaleChecked, flipChecked, rotateChecked, img64); return(result); }
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 } } }
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); } }