Ejemplo n.º 1
0
        public void CreateEmbroidery(Preview preview, string imageName, int coefficient, int cellsCount, DColor[] palette, char[] symbols, DColor symbolColor, Embroidery.GridType gridType)
        {

            BitmapSource bitmapSource = null;

            try
            {
                DBitmap _imageFromFile = new DBitmap(imageName);

                Func<DBitmap, DBitmap> getCopyBitmap = new Func<DBitmap, DBitmap>(GetCopyOfBitmap);
                IAsyncResult getCopyBitmapResult = getCopyBitmap.BeginInvoke(_imageFromFile, null, null);
                DBitmap inputImage = getCopyBitmap.EndInvoke(getCopyBitmapResult);

                Embroidery.EmbroideryCreatorServiceClient wcf_service = new Embroidery.EmbroideryCreatorServiceClient();

                Func<DBitmap, int, int, DColor[], char[], DColor, Embroidery.GridType, DBitmap> getEmbroidery = new Func<DBitmap, int, int, DColor[], char[], DColor, Embroidery.GridType, DBitmap>(wcf_service.GetEmbroidery);
                IAsyncResult getEmbroideryResult = getEmbroidery.BeginInvoke(inputImage, coefficient, cellsCount, palette, symbols, DColor.Black, gridType, null, null);
                DBitmap resultImage = getEmbroidery.EndInvoke(getEmbroideryResult);


                if (resultImage == null)
                {
                    MessageBox.Show("Some error occured on the server");
                    //HideLoading();
                    return;
                }

                bitmapSource = GetBitmapSource(resultImage);
            }
            catch (OutOfMemoryException ex)
            {
                MessageBox.Show("Sorry, but image is too large :(");
                //HideLoading();
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Some exception was occured. Message: " + ex.Message);
                //HideLoading();
                return;
            }

            bitmapSource.Freeze();

            preview.Dispatcher.BeginInvoke(new Action(() =>
                {
                    preview.loadingPanel.Visibility = System.Windows.Visibility.Collapsed;
                    preview.previewImage.Source = bitmapSource;
                }),
                System.Windows.Threading.DispatcherPriority.Normal);
           

        }
Ejemplo n.º 2
0
        private async void ComboBoxResolutions_DropDownOpened(object sender, EventArgs e)
        {
            System.Drawing.Bitmap image;
            int cellsCount;

            if(imageName != null)
            {
                try
                {
                    image = new DBitmap(imageName);
                }
                catch (OutOfMemoryException ex)
                {
                    MessageBox.Show("Sorry, but image is too large :(");
                    return;
                }
                catch
                {
                    informationText.Text = "Could not open image"; ;
                    return;
                }
            }
            else
            {
                informationText.Text = "Open image first";
                return;
            }
            
            try
            {
                cellsCount = Convert.ToInt32(cellsCountTextBox.Text);
            }
            catch (Exception ex)
            {
                informationText.Text = "Count of cells is incorrect";
                cellsCountTextBox.Background = new SolidColorBrush(Color.FromArgb(255, 200, 10, 10));
                wasWrongCellsCount = true;
                return;
            }

            if (cellsCount <= 1) 
            { 
                informationText.Text = "count of cells has to be more than 1";
                return; 
            }
            else if (cellsCount > image.Width) { informationText.Text = "count of cells has to be less than " + (image.Width + 1).ToString(); return; }


            Embroidery.EmbroideryCreatorServiceClient wcf_service = new Embroidery.EmbroideryCreatorServiceClient();
            List<string> waitEnumerable = new List<string>();
            waitEnumerable.Add("Wait");

            comboBoxResolutions.ItemsSource = waitEnumerable;
            try
            {
                resolutions = await wcf_service.PossibleResolutionsAsync(image, cellsCount, 2, 10);
            }
            catch(Exception ex)
            {
                comboBoxResolutions.ItemsSource = null;
                informationText.Text = ex.Message;
                return;
            }
            if (resolutions == null)
            {
                informationText.Text = "Some error was occured while getting resolutions. See log for details.";
                comboBoxResolutions.ItemsSource = null;
                return;
            }

            comboBoxResolutions.ItemsSource = resolutions.Keys;

        }