public PixelWrapper(Ipixel _data, double _xScale, double _yScale)
 {
     Graphic = InitializeRectangle(_yScale, _xScale);
     Graphic.Tag = _data.Tag;
     Graphic.ToolTip = _data.Description;
 }
 private void AddPixel(double x, double y, double xScale, double yScale, ref Canvas _renderedImage, Ipixel _data, int _maxR, int _maxG, int _maxB)
 {
     PixelWrapper xrfPix = new PixelWrapper(_data, xScale, yScale);
     Canvas.SetTop(xrfPix.Graphic, y);
     Canvas.SetLeft(xrfPix.Graphic, x);
     xrfPix.Graphic.Fill = new SolidColorBrush(_generateColorAction(_data.Temperature, _maxR, _maxG, _maxB));
     xrfPix.Graphic.MouseEnter += Graphic_MouseEnter;
     xrfPix.Graphic.MouseLeftButtonDown += Graphic_MouseLeftButtonDown;
     xrfPix.Graphic.MouseRightButtonDown += Graphic_MouseRightButtonDown;
     _renderedImage.Children.Add(xrfPix.Graphic);
 }
        private Canvas RenderImage(Ipixel[][] imageGrid, double imageSize, int maxR, int maxG, int maxB)
        {
            if(_effectiveImage == null)
                _effectiveImage = new Canvas();

            int imageRows = imageGrid.Length;
            int imageColumns = imageGrid[0].Length;

            double pixelScaleX, pixelScaleY;

            if (RenderToScale)
            {
                int scaleDivisor = (imageRows > imageColumns) ? imageRows : imageColumns;
                pixelScaleY = pixelScaleX = imageSize / scaleDivisor;

                _effectiveImage.Height = (imageRows < imageColumns) ? (imageSize * imageRows / imageColumns) : imageSize;
                _effectiveImage.Width = (imageRows < imageColumns) ? imageSize : (imageSize * imageColumns / imageRows);
            }
            else
            {
                pixelScaleY = imageSize / imageRows;
                pixelScaleX = imageSize / imageColumns;

                _effectiveImage.Height = _effectiveImage.Width = imageSize;
            }

            for (int i = 0; i < imageRows; i++)
            {
                for (int j = 0; j < imageColumns; j++)
                {
                    AddPixel(j * pixelScaleX, i * pixelScaleY, pixelScaleX, pixelScaleY, ref _effectiveImage, imageGrid[i][j], maxR, maxG, maxB);
                }
            }

            return _effectiveImage;
        }
        /// <summary>
        /// Refreshes the graph using data from a single-layer image.
        /// </summary>
        /// <param name="imageGrid">An array containing image data.</param>
        public void RefreshImage(Ipixel[][] imageGrid)
        {
            if (RenderedImage != null)
                Clear();

            if (imageGrid != null)
            {
                RenderedImage = RenderImage(imageGrid, _imageSize, _maxChannelValue, _maxChannelValue, _maxChannelValue);
                _imageBuffer = imageGrid;
            }
        }