public static bool[] getSelectedPixelsArrayForWand(Point point, double[] pixelDataHSV, int stride, int pixelHeight, double actualHeight, double actualWidth) { selectedPixels = new bool[stride * pixelHeight + 4]; alreadyChecked = new bool[stride * pixelHeight + 4]; borderPixels = new bool[stride * pixelHeight + 4]; double pointX, pointY; pointX = (point.X / actualWidth) * stride; pointY = (point.Y / actualHeight) * pixelHeight; if ((int)pointX % 4 != 4) { pointX -= pointX % 4; } double value = pixelDataHSV[(int)pointY * stride + (int)pointX]; WandHelper wandHelper = new WandHelper(range, value, pixelDataHSV, stride, pixelHeight); selectedPixels = wandHelper.WandAlg((int)pointX, (int)pointY); borderPixels = wandHelper.GetBorderArray(); return(selectedPixels); }
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); } } } } }