In this example, the color of the pixel beneath the mouse is retrieved from the back buffer.
if (Mouse.GetState().LeftButton == ButtonState.Pressed &&
// If the left button is pressed
Mouse.GetState().X > 0 && Mouse.GetState().Y > 0 &&
// and we are inside the game window
(Mouse.GetState().X <
GraphicsDevice.PresentationParameters.BackBufferWidth) &&
(Mouse.GetState().Y <
GraphicsDevice.PresentationParameters.BackBufferHeight))
{
backBufferData = new ResolveTexture2D(
GraphicsDevice,
GraphicsDevice.PresentationParameters.BackBufferWidth,
GraphicsDevice.PresentationParameters.BackBufferHeight,
1,
GraphicsDevice.PresentationParameters.BackBufferFormat);
Rectangle sourceRectangle =
new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1);
Color[] retrievedColor = new Color[1];
GraphicsDevice.ResolveBackBuffer(backBufferData);
backBufferData.GetData<Color>(
0,
sourceRectangle,
retrievedColor,
0,
1);
}