Retrieve RGB color values from Pixels property
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
/Alex [Community Champion]
____
[Community Champions] 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 Champions]
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 Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
/Alex [Community Champion]
____
[Community Champions] 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 Champions]
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 Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for getting back to confirm this worked for you @simonaferrara !
Sonya Mihaljova
Community and Education Specialist
