/// <summary>
/// Gets the color of a specific pixel.
/// </summary>
/// <param name="pt">The point from which to get a color.</param>
/// <returns>The color of the point.</returns>
private System.Windows.Media.Color GetPixelColor(InputDevice inputDevice)
{
// Translate the input point to bitmap coordinates
double transformFactor = ColorWheel.Source.Width / ColorWheel.ActualWidth;
Point inputPoint = inputDevice.GetPosition(ColorWheel);
Point bitmapPoint = new Point(inputPoint.X * transformFactor, inputPoint.Y * transformFactor);
// The point is outside the color wheel. Return black.
if (bitmapPoint.X < 0 || bitmapPoint.X >= ColorWheel.Source.Width ||
bitmapPoint.Y < 0 || bitmapPoint.Y >= ColorWheel.Source.Height)
{
return Colors.Black;
}
// The point is inside the color wheel. Find the color at the point.
CroppedBitmap cb = new CroppedBitmap(ColorWheel.Source as BitmapSource, new Int32Rect((int)bitmapPoint.X, (int)bitmapPoint.Y, 1, 1));
byte[] pixels = new byte[4];
cb.CopyPixels(pixels, 4, 0);
return Color.FromRgb(pixels[2], pixels[1], pixels[0]);
}