예제 #1
0
        private void canvas_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (selectionPowerChbx.IsChecked == true && (rectSelectionRb.IsChecked == true || elipseSelectionRb.IsChecked == true))
            {
                if (clickCounter == 0)
                {
                    clickCounter++;
                    firstPoint = e.GetPosition((Canvas)sender);
                }
                else if (clickCounter == 1)
                {
                    // check which shape
                    secondPoint = e.GetPosition((Canvas)sender);
                    if (rectSelectionRb.IsChecked == true)
                    {
                        rects.Add(MyCustomShapes.drawMyRectangle(ref canvas, firstPoint, secondPoint));
                        myConversion.setSelectedPixels(MyCustomShapes.getSelectedPixelsArrayForRect(firstPoint, secondPoint, myConversion.getStride(), orginalPhoto.PixelHeight, canvas.ActualHeight, canvas.ActualWidth));
                    }
                    else if (elipseSelectionRb.IsChecked == true)
                    {
                        ellipses.Add(MyCustomShapes.drawMyEllipse(ref canvas, firstPoint, secondPoint));
                        myConversion.setSelectedPixels(MyCustomShapes.getSelectedPixelsArrayForEllipse(firstPoint, secondPoint, myConversion.getStride(), orginalPhoto.PixelHeight, canvas.ActualHeight, canvas.ActualWidth));
                    }

                    clickCounter = 0;
                }
            }
            else if (selectionPowerChbx.IsChecked == true && wandSelectionRb.IsChecked == true)
            {
                double[] hsvpixels = myConversion.getPixelDataHSV();
                byte[]   rgbpixels = myConversion.getPixelDataRGB();
                if (hsvpixels == null)
                {
                    myConversion.convertRGBtoHSV();
                    hsvpixels = myConversion.getPixelDataHSV();
                }
                MyCustomShapes.range = rangeSlider.Value;

                selectedColorLabel.Background = MyCustomShapes.borderColor;

                myConversion.setSelectedPixels(MyCustomShapes.getSelectedPixelsArrayForWand(e.GetPosition((Canvas)sender), hsvpixels, myConversion.getStride(), orginalPhoto.PixelHeight, canvas.ActualHeight, canvas.ActualWidth));

                int    s            = myConversion.getStride();
                bool[] borderPixels = WandHelper.getBorder();

                myPoints = new List <Ellipse>();

                for (int y = 0; y < currentPhoto.PixelHeight; y++)
                {
                    int yIndex = y * s;
                    for (int x = 0; x < s; x += 4)
                    {
                        if (borderPixels[yIndex + x])
                        {
                            int     dotSize = 3;
                            double  w = ((double)x / currentPhoto.PixelWidth / 4) * canvas.ActualWidth, h = ((double)y / currentPhoto.PixelHeight) * canvas.ActualHeight;
                            Ellipse currentDot = new Ellipse();
                            currentDot.Stroke          = new SolidColorBrush(Colors.Green);
                            currentDot.StrokeThickness = 3;
                            currentDot.Height          = dotSize;
                            currentDot.Width           = dotSize;
                            currentDot.Fill            = new SolidColorBrush(Colors.Green);
                            currentDot.Margin          = new Thickness(w, h, 0, 0);
                            myPoints.Add(currentDot);
                            canvas.Children.Add(currentDot);
                        }
                    }
                }
            }
        }
예제 #2
0
 private void randomColor_Click(object sender, RoutedEventArgs e)
 {
     MyCustomShapes.setRandomColor();
     selectedColorLabel.Background = MyCustomShapes.borderColor;
 }