Forum Discussion

simonaferrara's avatar
simonaferrara
Frequent Contributor
4 years ago

Retrieve RGB color values from Pixels property

Hi all,   how can I retrieve the RGB values (red-green-blue) from the returned integer value of picture Pixels property (https://support.smartbear.com/testcomplete/docs/reference/program-objects/pi...
  • AlexKaras's avatar
    AlexKaras
    4 years ago

    Hi,

     

    If RGB = r + (g * 256) + (b * 65536), then for

    colorElement == 9118312 (untested code snippet):

     

    var b = Math.floor(colorElement / 65536); // == 139

    var g = Math.floor((colorElement - b * 65536) / 256); // == 34

    var r = colorElement - b * 65536 - g * 256; // == 104

    // 104 + (34 * 256) + (139 * 65536) == 9118312

    // RGB(104, 34, 139) == colorElement