- Identifying the color of a pixel
Identifying the color of a pixel The following code shows how to identify the color of a pixel. The user clicks the image control (IMG_ImageDrawing) to select the pixel. The coordinates of the selected pixel can be retrieved with MouseXPos and MouseYPos. In this example, we will assume that the image control (IMG_ImageDrawing) contains one image.
// -- Click code of "IMG_ImageDrawing" // Declare the variables PixelColor is int CoordHorPixel is int CoordVertPixel is int PixelColorRed is int PixelColorGreen is int PixelColorBlue is int // Retrieve the coordinates of the selected pixel CoordHorPixel = MouseXPos() CoordVertPixel = MouseYPos() // Identify the color of the selected pixel PixelColor = dPixelColor(IMG_ImageDrawing, CoordHorPixel, CoordVertPixel) PixelColorRed = modulo(PixelColor, 256) PixelColorGreen = modulo(PixelColor/256, 256) PixelColorBlue = modulo(PixelColor/256/256, 256) // Display the result Info("The color components of the pixel are: " + CR + ... TAB + "- Red: " + PixelColorRed + CR + ... TAB + "- Green: " + PixelColorGreen + CR + ... TAB + "- Blue: " + PixelColorBlue)
This page is also available for…
|
|
|
|