当前位置: 首页>>代码示例>>C#>>正文


C# WriteableBitmap.GetPixel方法代码示例

本文整理汇总了C#中System.Windows.Media.Imaging.WriteableBitmap.GetPixel方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.GetPixel方法的具体用法?C# WriteableBitmap.GetPixel怎么用?C# WriteableBitmap.GetPixel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Media.Imaging.WriteableBitmap的用法示例。


在下文中一共展示了WriteableBitmap.GetPixel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: canvas1_MouseLeftButtonDown

        private void canvas1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (toolState == 0)
            {
                canvas1.CaptureMouse();
                if (!activelyDrawing && toolState == 0) //just started to draw, save state first (in order to undo)
                {
                    updateUndoList();
                    activelyDrawing = true;
                }

                cur_p.x = (short)e.GetPosition(canvas1).X;
                cur_p.y = (short)e.GetPosition(canvas1).Y;

                prev_p = cur_p;
            }
            else if (toolState == 2)
            {
                bm = new WriteableBitmap(canvas1, null);
                Globals.scb.Color = bm.GetPixel((int)e.GetPosition(canvas1).X, (int)e.GetPosition(canvas1).Y);
                border2.Background = Globals.scb;
                makeToast("Color Sampled", "");
                toolState++;
                fillClick(null, null); //to move to pencil mode
                //NavigationService.Navigate(new Uri("/ColorPicker.xaml", UriKind.Relative));
            }
        }
开发者ID:Nesszors,项目名称:PaintApp,代码行数:27,代码来源:MainPage.xaml.cs

示例2: EdgeDetection

        public WriteableBitmap EdgeDetection(WriteableBitmap bmap, double bound)
        {
            int height = bmap.PixelHeight - 1;
            int width = bmap.PixelWidth - 1;
            Matrix thetaM = new Matrix(width, height);
            Matrix greyM = new Matrix(width + 1, height + 1);
            for (int i = 0; i < greyM.Width; i++)
                for (int j = 0; j < greyM.Height; j++)
                    greyM[i, j] = Greyscale(bmap.GetPixel(i, j).R, bmap.GetPixel(i, j).G, bmap.GetPixel(i, j).B);

            for (int i = 1; i < width; i++)
                for (int j = 1; j < height; j++)
                {
                    Vector lx = new Vector(3);
                    Vector ly = new Vector(3);
                    lx[0] = greyM[i - 1, j];
                    lx[1] = greyM[i, j];
                    lx[2] = greyM[i + 1, j];
                    ly[0] = greyM[i, j - 1];
                    ly[1] = greyM[i, j];
                    ly[2] = greyM[i, j + 1];
                    Vector slx = SobelX(lx);
                    Vector sly = SobelY(ly);
                    double gx = Math.Pow(slx * slx, 0.5);
                    double gy = Math.Pow(sly * sly, 0.5);
                    thetaM[i - 1, j - 1] = Math.Atan2(gy, gx);
                }
            WriteableBitmap plot = BitmapFactory.New(width, height);
            for (int i = 0; i < width; i++)
                for (int j = 0; j < height; j++)
                {
                    if (thetaM[i, j] > bound)
                        plot.SetPixel(i, j, Colors.White);
                    else
                        plot.SetPixel(i, j, Colors.Black);
                }
            return plot;
        }
开发者ID:numcat,项目名称:Machine-Learning-Collection,代码行数:38,代码来源:SobelEdgeDetection.cs

示例3: GameViewModel

        public GameViewModel(WriteableBitmap img)
        {
            // Invert width and height cause of bmp?
            GridViewModel = new GridViewModel(img.PixelHeight, img.PixelWidth);

            // Get every pixel
            for (int x = 0; x < img.PixelWidth; x++)
            {
                for (int y = 0; y < img.PixelHeight; y++)
                {
                    Color color = img.GetPixel(x, y);

                    float r, g, b, a;

                    if (color.A < 20)
                    {
                        a = 1;
                        r = 1;
                        g = 1;
                        b = 1;
                    }
                    else
                    {
                        a = 1;
                        r = color.R / 255f;
                        g = color.G / 255f;
                        b = color.B / 255f;
                    }

                    // invert x and y
                    GridViewModel.SetPixelData(y, x, new Data.CellColor()
                    {
                        A = a,
                        R = r,
                        G = g,
                        B = b,
                    });
                }
            }

            GridViewModel.SetupGrid();
            GridViewModel.UpdateView(null);
        }
开发者ID:valryon,项目名称:pixpuzzle,代码行数:43,代码来源:GameViewModel.cs

示例4: MainViewModel

        public MainViewModel()
        {
            SizeX = 768;
            SizeY = 512;
            SpotSizeX = 200;
            SpotSizeY = 233;

            SpotColors = new List<Color>
            {
                Color.FromArgb(150, 164, 232, 0),
                Color.FromArgb(150, 255, 185, 17),
                Color.FromArgb(150, 0, 149, 59),
                Color.FromArgb(150, 222, 184, 99),
                Color.FromArgb(150, 234, 0, 53),
            };

            var colors = new List<Color>
            {
                Colors.Red,
                Colors.Blue,
                Colors.Green
            };
            Overlay = new WriteableBitmap(SizeX, SizeY, 96, 96, PixelFormats.Pbgra32, new BitmapPalette(colors));
            Overlay.Clear(Colors.Black);

            PixSpots = new List<Blot>();
            Pixs = new List<byte[,]>();

            var spots =
                Directory.GetFiles(Directory.GetCurrentDirectory() + @"\img\").Where(p => p.Contains(".png")).ToArray();
            foreach (var spot in spots)
            {
                Pixs.Add(new byte[SpotSizeX, SpotSizeY]);
                var img = new WriteableBitmap(new BitmapImage(new Uri(spot)));
                for (var i = 0; i < img.PixelWidth; i++)
                    for (var j = 0; j < img.PixelHeight; j++)
                        if (img.GetPixel(i, j).A > 0)
                            Pixs[Pixs.Count - 1][i, j] = 1;
            }
        }
开发者ID:KonigLabs,项目名称:SpriteEvent,代码行数:40,代码来源:MainViewModel.cs

示例5: CalculateStarSize

        public void CalculateStarSize(WriteableBitmap bitmap)
        {
            int Max = 0;
            int Min = 800;
            int Count = 0;
            for (int i = 0; i < StarWindowSize-1; i++)
            {

                for (int j = 0; j < StarWindowSize-1; j++)
                {
                    var c = bitmap.GetPixel(i, j);
                    var greyVal = c.R + c.G + c.B;
                    if (greyVal > Threshold)
                        Count = Count + 1;
                    if (greyVal > Max)
                        Max = greyVal;

                    if (greyVal < Min)
                        Min = greyVal;
                }
            }
            MaximumValue = Max;
            MinimumValue = Min;
            Threshold = (Max + Min)/2;
            StarSize = ((double) Count + K*StarSizeOld)/(K + 1);
            StarSizeOld = StarSize;

        }
开发者ID:tomriddle1234,项目名称:digiCamControl,代码行数:28,代码来源:AstroLiveViewViewModel.cs

示例6: AdvGamePage

        public AdvGamePage()
        {
            InitializeComponent();

            var fileStream1 = Application.GetResourceStream(new Uri("TestImages/TestingUpper.png", UriKind.Relative));
            var s1 = new BitmapImage();
            using (var stream = fileStream1.Stream)
            {
                s1.SetSource(stream);
            }

            var upper = new WriteableBitmap(s1);

            var fileStream2 = Application.GetResourceStream(new Uri("TestImages/TestingLower.png", UriKind.Relative));
            var s2 = new BitmapImage();
            using (var stream = fileStream2.Stream)
            {
                s2.SetSource(stream);
            }

            var lower = new WriteableBitmap(s2);

            var upperEx = upper.GetBitmapContext();
            var lowerEx = lower.GetBitmapContext();

            UpperImage.Source = upper;
            LowerImage.Source = lower;

            upper.ForEach((x, y, color) =>
                {
                    var lowerColor = lower.GetPixel(x, y);
                    return new Color
                        {
                            R = (byte) (color.R - lowerColor.R),
                            G = (byte) (color.G - lowerColor.G),
                            B = (byte) (color.B - lowerColor.B),
                            A = color.A
                        };
                });
            upper.Invalidate();

            var changesPixels = new List<Point>();

            upper.ForEach((x, y, color) =>
                {
                    if (upper.GetPixel(x, y).R != 0)
                    {
                        lower.FillEllipseCentered(x, y, 10, 10, Colors.Red);
                        changesPixels.Add(new Point(x, y));
                    }

                    return color;
                });
            lower.Invalidate();

            //var indicator = new bool[480, 320];
            var startingPoint = changesPixels[0];
            var newPointToBeInvestigate = new List<Point> { startingPoint };
            changesPixels.Remove(startingPoint);
            //indicator[(int)startingPoint.X, (int)startingPoint.Y] = true;

            System.Diagnostics.Debug.WriteLine(DateTime.Now);

            var i = 0;
            while (newPointToBeInvestigate.Count > 0 && i < newPointToBeInvestigate.Count)
            {
                var newPixels = changesPixels.Where(p => DistanceBetweenPoints(newPointToBeInvestigate[i], p)).ToList();

                foreach (var np in newPixels)
                {
                    changesPixels.Remove(np);
                    newPointToBeInvestigate.Add(np);
                }

                //foreach (var newP in newPixels.Where(newP => !indicator[(int)newP.X, (int)newP.Y]))
                //{
                //    indicator[(int)newP.X, (int)newP.Y] = true;
                //}

                i++;

            }
            System.Diagnostics.Debug.WriteLine(DateTime.Now);

            foreach (var changeP in newPointToBeInvestigate)
            {
                lower.SetPixel((int)changeP.X, (int)changeP.Y, Colors.Green);
            }

            lower.Invalidate();
        }
开发者ID:NBitionDevelopment,项目名称:WindowsPhonePhotoHunt,代码行数:91,代码来源:AdvGamePage.xaml.cs

示例7: GetColorFromImage

        private Color GetColorFromImage(MouseEventArgs e)
        {
            Color color = Color.FromArgb(0, 0, 0, 0);

            try
            {
                var mousePos = e.GetPosition(this.mapImage);
                int x = (int)mousePos.X;
                int y = (int)mousePos.Y;

                var bitmap = new WriteableBitmap(this.mapImage, null);
                color = bitmap.GetPixel(x, y);

                if (_debugModeOn)
                {
                    string strColorARGB = string.Join(", ", color.A.ToString(), color.R.ToString(), color.G.ToString(), color.B.ToString());
                    txtSelectedCountry.Text = string.Format("ARGB: {0}", strColorARGB);
                }
            }
            catch { }

            return color;
        }
开发者ID:gp-andino,项目名称:Guardianes-Greenpeace,代码行数:23,代码来源:CountrySelector.xaml.cs

示例8: UIElement_OnMouseDown

        private void UIElement_OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                int Height = (int)IconPreview.ActualHeight;
                int Width = (int)IconPreview.ActualWidth;

                RenderTargetBitmap bmp = new RenderTargetBitmap(Width, Height, 96, 96, PixelFormats.Pbgra32);
                bmp.Render(this.IconPreview);

                var wb = new WriteableBitmap(bmp);
                var pos = e.GetPosition(sender as FrameworkElement);
                _iconsGenerator.Color = wb.GetPixel((int) pos.X, (int) pos.Y);

                ColorPicker1.SelectedColor = _iconsGenerator.Color;
            }
            catch (Exception ex)
            {
            }
        }
开发者ID:alexsorokoletov,项目名称:ImagePreparator,代码行数:20,代码来源:MainWindow.xaml.cs

示例9: redrawMovedImage

        private static void redrawMovedImage(WriteableBitmap tempWb, Image img)
        {
            int w = MainPage.layerList[clickedLayer].wb.PixelWidth;
            int h = MainPage.layerList[clickedLayer].wb.PixelHeight;

            MainPage.layerList[clickedLayer].wb.Clear();
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    if (tempWb.GetPixel(i, j) != Color.FromArgb(0, 0, 0, 0))
                    {
                        Color tempPixel = tempWb.GetPixel(i, j);

                        int setX = i + (int)img.Margin.Left;
                        int setY = j + (int)img.Margin.Top;
                        if (setX < w && setX >= 0 && setY < h && setY >= 0)
                        {
                            MainPage.layerList[clickedLayer].wb.SetPixel(setX, setY, tempPixel);
                        }

                    }
                }
            }
        }
开发者ID:kiangkuang,项目名称:SilverlightFill,代码行数:25,代码来源:Drag.cs

示例10: ToGrayScale

 /// <summary>
 /// Converts a WritableBitmap to grayscale image
 /// </summary>
 public static WriteableBitmap ToGrayScale(WriteableBitmap bmp)
 {
     for (int i = 0; i < bmp.PixelHeight; i++)
     {
         for (int j = 0; j < bmp.PixelWidth; j++)
         {
             byte grayScale = Convert.ToByte((bmp.GetPixel(j, i).R * 0.3) + (bmp.GetPixel(j, i).G * 0.59) + (bmp.GetPixel(j, i).B * 0.11));
             Color c = Color.FromArgb(255, grayScale, grayScale, grayScale);
             bmp.SetPixel(j, i, c);
         }
     }
     return bmp;
 }
开发者ID:jaydeep17,项目名称:TheReader7,代码行数:16,代码来源:PreImageProcessing.cs

示例11: RGBLuminanceSource

    public RGBLuminanceSource(WriteableBitmap d, int W, int H)
#endif
        : base(W, H)
    {
        int width = __width = W;
        int height = __height = H;
        // In order to measure pure decoding speed, we convert the entire image to a greyscale array
        // up front, which is the same as the Y channel of the YUVLuminanceSource in the real app.
        luminances = new byte[width * height];
        //if (format == PixelFormat.Format8bppIndexed)
        {
            Color c;
            for (int y = 0; y < height; y++)
            {
                int offset = y * width;
                for (int x = 0; x < width; x++)
                {
                    c = d.GetPixel(x, y);
                    luminances[offset + x] = (byte)(((int)c.R) << 16 | ((int)c.G) << 8 | ((int)c.B));
                }
            }
        }
    }
开发者ID:GSerjo,项目名称:Seminars,代码行数:23,代码来源:RGBLuminanceSource.cs

示例12: floodFill

        public static void floodFill(Point pt, Color targetColor, Color replacementColor, WriteableBitmap compressedBitmap, WriteableBitmap outputBitmap)
        {
            Queue<Point> q = new Queue<Point>();

            maxLeft = compressedBitmap.PixelWidth;
            //System.Diagnostics.Debug.WriteLine(maxLeft);
            maxRight = 0;
            maxTop = compressedBitmap.PixelHeight;
            //System.Diagnostics.Debug.WriteLine("while filling" + maxTop);
            maxBottom = 0;

            if (!Common.ColorMatch(compressedBitmap.GetPixel((int)pt.X, (int)pt.Y), targetColor) || Common.ColorMatch(compressedBitmap.GetPixel((int)pt.X, (int)pt.Y), replacementColor))
            {
                return;
            }

            q.Enqueue(pt);

            while (q.Count > 0)
            {
                Point n = q.Dequeue();

                if (Common.ColorMatch(compressedBitmap.GetPixel((int)n.X, (int)n.Y), targetColor))
                {
                    Point west = n;
                    Point east = n;

                    while ((west.X >= 0) && (west.X < compressedBitmap.PixelWidth) && Common.ColorMatch(compressedBitmap.GetPixel((int)west.X, (int)west.Y), targetColor))
                    {
                        west.X--;
                    }
                    while ((east.X >= 0) && (east.X < compressedBitmap.PixelWidth) && Common.ColorMatch(compressedBitmap.GetPixel((int)east.X, (int)east.Y), targetColor))
                    {
                        east.X++;
                    }
                    west.X++;
                    east.X--;

                    if (west.X < maxLeft)
                    {
                        maxLeft = west.X;
                    }

                    if (east.X > maxRight)
                    {
                        maxRight = east.X;
                    }

                    for (int i = (int)west.X; i <= east.X; i++)
                    {
                        compressedBitmap.SetPixel(i, (int)west.Y, replacementColor);
                        outputBitmap.SetPixel(i, (int)west.Y, replacementColor);
                        if ((i >= 0) && (i < compressedBitmap.PixelWidth) && (west.Y + 1 >= 0 && west.Y + 1 < compressedBitmap.PixelHeight) && Common.ColorMatch(compressedBitmap.GetPixel(i, (int)west.Y + 1), targetColor))
                        {
                            if (west.Y + 1 > maxBottom)
                            {
                                maxBottom = west.Y + 1;
                            }

                            q.Enqueue(new Point(i, west.Y + 1));
                        }
                        if ((i >= 0) && (i < compressedBitmap.PixelWidth) && (west.Y - 1 >= 0 && west.Y - 1 < compressedBitmap.PixelHeight) && Common.ColorMatch(compressedBitmap.GetPixel(i, (int)west.Y - 1), targetColor))
                        {
                            if (west.Y - 1 < maxTop)
                            {
                                maxTop = west.Y - 1;
                            }

                            q.Enqueue(new Point(i, west.Y - 1));
                        }
                    }
                }
            }
        }
开发者ID:kiangkuang,项目名称:SilverlightFill,代码行数:74,代码来源:Fill.cs

示例13: detectTop

 private static int detectTop(WriteableBitmap bmp)
 {
     for (int r = 0; r < bmp.PixelHeight - 1; r++)
     {
         int count = 0;
         for (int c = 0; c < bmp.PixelWidth - 1; c++)
         {
             Color color = bmp.GetPixel(c, r);
             if (color == Colors.White)
             {
                 count++;
             }
         }
         if (count > thCountX(bmp.PixelWidth))
         {
             return r;
         }
     }
     return 0;
 }
开发者ID:jaydeep17,项目名称:TheReader7,代码行数:20,代码来源:PreImageProcessing.cs

示例14: detectRight

 private static int detectRight(WriteableBitmap bmp)
 {
     for (int c = (bmp.PixelWidth - 1); c > 0; c--)
     {
         int count = 0;
         for (int r = (bmp.PixelHeight - 1); r > 0; r--)
         {
             Color color = bmp.GetPixel(c, r);
             if (color == Colors.White)
             {
                 count++;
             }
         }
         if (count > thCountY(bmp.PixelHeight) / 8)
         {
             return c;
         }
     }
     return 0;
 }
开发者ID:jaydeep17,项目名称:TheReader7,代码行数:20,代码来源:PreImageProcessing.cs

示例15: getTargetColor

 public static Color getTargetColor(MouseButtonEventArgs e, InkPresenter inkCanvas, WriteableBitmap wb)
 {
     return wb.GetPixel((int)e.GetPosition(inkCanvas).X, (int)e.GetPosition(inkCanvas).Y);
 }
开发者ID:kiangkuang,项目名称:SilverlightFill,代码行数:4,代码来源:Common.cs


注:本文中的System.Windows.Media.Imaging.WriteableBitmap.GetPixel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。