cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieve RGB color values from Pixels property

SOLVED
simonaferrara
Contributor

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/picture/pixels.html)

?

 

Thanks

Simona

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
AlexKaras
Community Hero

Re: Retrieve RGB color values from Pixels property

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

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

7 REPLIES 7
Marsha_R
Community Hero

Re: Retrieve RGB color values from Pixels property

@simonaferrara 

 

1) I don't 'see a particular example for retrieving the color, but my first thought would be to try $get in the example that says $set

2) Just a hint for the future, URLs are great to include in a post but don't put ( ) around them or that becomes part of the link and we can't click it.  🙂

 

@sonya_m  I couldn't find a "retrieve color" example in here even though the header of the article mentions it.  Could you point it out or get us one?  Thanks.

https://support.smartbear.com/testcomplete/docs/reference/program-objects/picture/pixels.html

AlexKaras
Community Hero

Re: Retrieve RGB color values from Pixels property

Hi Simona,

 

If I got your question right...

Below VBScript function creates color number based on RGB.

You can revert it to get RGB values out of color number.

 

Function RGB(ByVal r, ByVal g, ByVal b)
  RGB = r + (g * 256) + (b * 65536)
End Function

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
simonaferrara
Contributor

Re: Retrieve RGB color values from Pixels property

The question is that I don't know how to retrieve the RGB values from the integer values that is returned by Pixels property.

The javascript code that I've implemented is like this:

 

let colorElement = canvas.Picture(697, 23, 249, 23, false);
let x = colorElement.Size.Width - 10;
let y = colorElement.Size.Height - 10;
let color = colorElement.Pixels(x, y);

 

When executing this code, the color variable contains the following value:

9118312

 

How can I have the RGB values (r,g,b) from this integer number?

 

@AlexKaras your example is great to have the vice-versa (given the r,g,b, have the integer number) but I don't know how can I do the reverse (given the integer number, have the r,g,b).

 

@Marsha_R thanks for your hint for urls in post and to ask for a documentation for my question.

 

Regards,

Simona 

 

AlexKaras
Community Hero

Re: Retrieve RGB color values from Pixels property

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

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

sonya_m
Community Manager

Re: Retrieve RGB color values from Pixels property

Thanks a lot Alex and Marsha!

 

I've contacted the doc team, they will add an example to the page in question.

@simonaferrara please try what Alex is suggesting here + here's a page that can be of help: - https://support.smartbear.com/testcomplete/docs/scripting/colors.html 


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
simonaferrara
Contributor

Re: Retrieve RGB color values from Pixels property

@AlexKaras thank you so much!

Your solution works perfectly! 

 

@sonya_m I confirm you that the Alex code is ok!

 

Thank you to add it to the documentation, it can be very useful also for other people!

 

Regards,

Simona

 

sonya_m
Community Manager

Re: Retrieve RGB color values from Pixels property

Thank you for getting back to confirm this worked for you @simonaferrara !


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors