ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Controls, pages and windows / Drawing functions
  • Identifying the color of a pixel
dPixelColor (Example)
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)
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help