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

        }
예제 #2
0
        private void createEmbroidery_Click(object sender, RoutedEventArgs e)
        {
            //loadingCanvas.Visibility = System.Windows.Visibility.Visible;
            //ShowLoading(loadingCanvas);
            informationText.Text = "";

            DColor[] palette;
            char[] symbols = null;
            Embroidery.GridType gridType = Embroidery.GridType.None;
            int coefficient;
            int _cellsCount;

            palette = GetPalette(choosedColors.Children);

            if (palette == null){
                informationText.Text = "";
                informationText.Text = "Create palette before embroidery creating";
                //HideLoading();
                return;
            }

            if ((bool)checkBoxSymbols.IsChecked) symbols = GetSymbols();

            try
            {
                resolutions.TryGetValue((string)comboBoxResolutions.SelectedItem, out coefficient);
            }
            catch
            {
                informationText.Text = "Choose resolution first";
                //HideLoading();
                return;
            }

            if ((bool)checkBoxGrid.IsChecked)
            {
                if ((bool)radioButtonLine.IsChecked) gridType = Embroidery.GridType.SolidLine;
                else gridType = Embroidery.GridType.Points;
            }


            if ((bool)checkBoxSymbols.IsChecked)
            {
                symbols = GetSymbols();
                if (symbols == null)
                {
                    informationText.Text = "Symbols initialization is incorrect";
                    //HideLoading();
                    return;
                }
            }

            try
            {
                _cellsCount = Convert.ToInt32(cellsCountTextBox.Text);
            }
            catch
            {
                informationText.Text = "cout of cells is wrong.";
                //HideLoading();
                return;
            }



            Thread openPreview = new Thread(() => {
                Preview preview = new Preview();
                preview.Show();

                Thread creatingEmbroidery = new Thread(() =>
                {
                    CreateEmbroidery(preview, imageName, coefficient, _cellsCount, palette, symbols, DColor.Black, gridType);
                });
                creatingEmbroidery.Start();

                System.Windows.Threading.Dispatcher.Run();
            });
            openPreview.SetApartmentState(ApartmentState.STA);
            openPreview.IsBackground = true;
            openPreview.Start();

           

        }