示例#1
0
        private void ListBox1_OnPreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            var mp   = (System.Windows.Controls.ListBox)sender;
            var item = (ListBoxMatch)mp.SelectedItem;

            if (item == null || this.imgBoardBitmap.Source == null || item.MatchPair.BoardPiece.Name == "Unknown")
            {
                return;
            }

            rectSourcePiece.Fill = new ImageBrush(ImageUtility.BitmapToImageSource(item.MatchPair.BoardPiece.GetImage(), ImageFormat.Bmp));

            var piecePoint = new Point(this.highlightedPiece.X * BoardPiece.Width, this.highlightedPiece.Y * BoardPiece.Height);
            var boardPiece = this.board.BoardImage.Clone(
                new Rectangle(piecePoint, new System.Drawing.Size(BoardPiece.Width, BoardPiece.Height)),
                PixelFormat.DontCare);

            rectBoardPiece.Fill = new ImageBrush(ImageUtility.BitmapToImageSource(boardPiece, ImageFormat.Bmp));

            lblColorDist.Content     = item.MatchPair.Weight.ColorDistance.ToString("##.####");
            lblLuminanceDist.Content = item.MatchPair.Weight.LuminanceDistance.ToString("##.####");

            rectBoardPieceAverageColor.Fill     = new SolidColorBrush(ColorUtility.ConvertToMediaColor(ColorUtility.GetAveragePieceColor(boardPiece, 0, 0)));
            rectBoardPieceAverageLuminance.Fill = new SolidColorBrush(ColorUtility.ConvertToMediaColor(ColorUtility.GetAveragePieceLuminance(boardPiece, 0, 0)));

            rectSourcePieceAverageColor.Fill     = new SolidColorBrush(ColorUtility.ConvertToMediaColor(ColorUtility.GetAveragePieceColor(item.MatchPair.BoardPiece.GetImage(), 0, 0)));
            rectSourcePieceAverageLuminance.Fill = new SolidColorBrush(ColorUtility.ConvertToMediaColor(ColorUtility.GetAveragePieceLuminance(item.MatchPair.BoardPiece.GetImage(), 0, 0)));

            // histograms
            var sourceHistogram = ColorUtility.GetLuminanceHistogram(item.MatchPair.BoardPiece.GetImage(), 0, 0);

            polySourceHistogram.Points = this.GetHistogramPointCollection(sourceHistogram);

            var pieceHistogram = ColorUtility.GetLuminanceHistogram(boardPiece, 0, 0);

            polyPieceHistogram.Points = this.GetHistogramPointCollection(pieceHistogram);

            var histogramDistance = ColorUtility.GetHistogramDistance(sourceHistogram, pieceHistogram);

            lblHistogramDist.Content = histogramDistance.ToString("##.####");
        }
示例#2
0
文件: Board.cs 项目: jweber/bbplayer
        private int UpdateBoardFacades()
        {
            int unknownCount = 0;

            for (int y = 0; y < 8; y++)
            {
                for (int x = 0; x < 8; x++)
                {
                    var positionPiece = this.boardPositions[y, x].Piece;

                    this.boardPositions[y, x].Facade.ToolTip = positionPiece.Name;

                    if (positionPiece.GetImage() != null)
                    {
                        this.boardPositions[y, x].Facade.Fill =
                            new ImageBrush(ImageUtility.BitmapToImageSource(positionPiece.GetImage(), ImageFormat.Bmp));
                    }


                    if (positionPiece == BoardPiece.Unknown)
                    {
                        unknownCount++;

                        this.boardPositions[y, x].Facade.Stroke          = System.Windows.Media.Brushes.Red;
                        this.boardPositions[y, x].Facade.StrokeThickness = 3;
                    }
                    else
                    {
                        this.boardPositions[y, x].Facade.Stroke          = System.Windows.Media.Brushes.Black;
                        this.boardPositions[y, x].Facade.StrokeThickness = 1;
                    }
                }
            }

            return(unknownCount);
        }