The GetPixel
method retrieves the color of a specific pixel located at the given coordinates (x
, y
) in the bitmap. This method is useful for accessing and manipulating individual pixel data within a bitmap image.
The GetPixel
method retrieves the color of a specific pixel located at the given coordinates (x
, y
) in the bitmap. This method is useful for accessing and manipulating individual pixel data within a bitmap image.
To use the GetPixel
method, you need to have an instance of the Bitmap
class. Call the method with the desired x
and y
coordinates to obtain the color of the pixel at that position.
Ensure that the coordinates are within the bounds of the bitmap's dimensions, otherwise an exception may be thrown.
// Example of using GetPixel method // Assume 'bitmap' is an instance of Sandbox.Bitmap int x = 10; int y = 20; // Retrieve the color of the pixel at coordinates (10, 20) Color pixelColor = bitmap.GetPixel(x, y); // Use the color for further processing // For example, print the color components // Console.WriteLine($"R: {pixelColor.r}, G: {pixelColor.g}, B: {pixelColor.b}, A: {pixelColor.a}");