# Capture RGB Values

**URL:** <https://forum.xojo.com/t/capture-rgb-values/18779>\
**Category:** General\
**Created:** [August 21, 2014, 9:32pm UTC](https://forum.xojo.com/t/capture-rgb-values/18779 "2014-08-21T21:32:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paulo\_Vargas](https://forum.xojo.com/user_avatar/forum.xojo.com/paulo_vargas/32/232_2.png) [@Paulo\_Vargas](https://forum.xojo.com/u/Paulo_Vargas)\
**Post date:** [August 21, 2014, 9:32pm UTC](https://forum.xojo.com/t/capture-rgb-values/18779/1 "2014-08-21T21:32:57Z")

</div>

Hello,

I wonder if there is a way for capture the RGB values ??of an open image on my screen, something like I click the mouse and values go for a Textfield ?

I thank any help.

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [August 21, 2014, 9:49pm UTC](https://forum.xojo.com/t/capture-rgb-values/18779/2 "2014-08-21T21:49:02Z")

</div>

MBS Plugin has functions to get Screenshot. If you get screenshot of a 1x1 pixel area, you can read the color of that pixel from the picture.

---

<div class="post-metadata">

**Author:** ![Julen\_I](https://forum.xojo.com/user_avatar/forum.xojo.com/julen_i/32/202_2.png) [@Julen\_I](https://forum.xojo.com/u/Julen_I)\
**Post date:** [August 21, 2014, 11:00pm UTC](https://forum.xojo.com/t/capture-rgb-values/18779/3 "2014-08-21T23:00:26Z")

</div>

Which platform? The Windows Functionality Suite has code to take a screenshot.

---

<div class="post-metadata">

**Author:** ![Paulo\_Vargas](https://forum.xojo.com/user_avatar/forum.xojo.com/paulo_vargas/32/232_2.png) [@Paulo\_Vargas](https://forum.xojo.com/u/Paulo_Vargas)\
**Post date:** [August 21, 2014, 11:10pm UTC](https://forum.xojo.com/t/capture-rgb-values/18779/4 "2014-08-21T23:10:32Z")

</div>

> [@123386:@Julen Ibarretxe Uriguen](#):
>
> Which platform? The Windows Functionality Suite has code to take a screenshot.

Just on MAC !

---

<div class="post-metadata">

**Author:** ![Jason\_King](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@Jason\_King](https://forum.xojo.com/u/Jason_King)\
**Post date:** [August 22, 2014, 12:53am UTC](https://forum.xojo.com/t/capture-rgb-values/18779/5 "2014-08-22T00:53:30Z")

</div>

Here is an example project I put together for a previous thread:  
[https://www.dropbox.com/s/jykh8sybjd558so/color%20under%20mouse.xojo\_binary\_project](https://www.dropbox.com/s/jykh8sybjd558so/color%20under%20mouse.xojo_binary_project)

Press enter to trigger the action event of the button and the color under the mouse pointer is captured and displayed in the onscreen canvas. It could be easily adapted to be triggered by clicking the mouse on a canvas or window.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [August 22, 2014, 10:14am UTC](https://forum.xojo.com/t/capture-rgb-values/18779/6 "2014-08-22T10:14:37Z")

</div>

> [@123388:@Paulo Vargas](#):
>
> Just on MAC !

Do you need to get the color from a picture loaded into your app, or anywhere else on the screen ?

If you need to capture a pixel somewhere on the screen, you can use the MBS plugin, or capture the screen to a file or to the clipboard with the shell command `screencapture`. Then you load the picture and use RGBSurface to get the color.

[https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/screencapture.1.html](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/screencapture.1.html)

> **[Screen Capture in Mac OS X](https://osxdaily.com/2010/06/09/screen-capture-in-mac-os-x/)**
>
> I use screenshots constantly to share bits of information with people, and they can be really helpful when troubleshooting as well. Here’s all you’ll need to know about taking screensho…

---

<div class="post-metadata">

**Author:** ![Paulo\_Vargas](https://forum.xojo.com/user_avatar/forum.xojo.com/paulo_vargas/32/232_2.png) [@Paulo\_Vargas](https://forum.xojo.com/u/Paulo_Vargas)\
**Post date:** [August 22, 2014, 10:51pm UTC](https://forum.xojo.com/t/capture-rgb-values/18779/7 "2014-08-22T22:51:13Z")

</div>

> [@123393:@Jason King](#):
>
> Press enter to trigger the action event of the button and the color under the mouse pointer is captured and displayed in the onscreen canvas. It could be easily adapted to be triggered by clicking the mouse on a canvas or window.

Jason your example is really fantastic and I am very grateful to have sent me wonder how I would have the RGB values ??captured in a textfield ?

---

<div class="post-metadata">

**Author:** ![Paulo\_Vargas](https://forum.xojo.com/user_avatar/forum.xojo.com/paulo_vargas/32/232_2.png) [@Paulo\_Vargas](https://forum.xojo.com/u/Paulo_Vargas)\
**Post date:** [August 22, 2014, 10:57pm UTC](https://forum.xojo.com/t/capture-rgb-values/18779/8 "2014-08-22T22:57:01Z")

</div>

[quote=123503:@Michel Bujardet]Do you need to get the color from a picture loaded into your app, or anywhere else on the screen ?

If you need to capture a pixel somewhere on the screen, you can use the MBS plugin, or capture the screen to a file or to the clipboard with the shell command `screencapture`. Then you load the picture and use RGBSurface to get the color.

[https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/screencapture.1.html](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/screencapture.1.html)  
[http://osxdaily.com/2010/06/09/screen-capture-in-mac-os-x/[/quote]](http://osxdaily.com/2010/06/09/screen-capture-in-mac-os-x/%5B/quote%5D)

Is anywhere on the screen, usually an open image in Photoshop or Ilustrator, I’ll do some based on your tip and Jason King tests.

Tanks again!

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [August 22, 2014, 11:25pm UTC](https://forum.xojo.com/t/capture-rgb-values/18779/9 "2014-08-22T23:25:01Z")

</div>

Here is a new project, slightly modified from Jason’s.

When you click on the button, it launches a timer which picks the color under the cursor over any part of the screen, displays its value in a text field, and makes a canvas the same color.

I reduced the size of the canvas, because all over the size of the window seemed too much flashing when moving the mouse 😉

[Screencolors.xojo\_binary\_project](http://match-software.com/xojo/Screencolors.xojo_binary_project)

To make it work within the timer Action event, I made some variables window properties, but I left the older code as comments.

---

<div class="post-metadata">

**Author:** ![Paulo\_Vargas](https://forum.xojo.com/user_avatar/forum.xojo.com/paulo_vargas/32/232_2.png) [@Paulo\_Vargas](https://forum.xojo.com/u/Paulo_Vargas)\
**Post date:** [August 22, 2014, 11:37pm UTC](https://forum.xojo.com/t/capture-rgb-values/18779/11 "2014-08-22T23:37:55Z")

</div>

[quote=123810:@Michel Bujardet]Here is a new project, slightly modified from Jason’s.

When you click on the button, it launches a timer which picks the color under the cursor over any part of the screen, displays its value in a text field, and makes a canvas the same color.

I reduced the size of the canvas, because all over the size of the window seemed too much flashing when moving the mouse 😉

[Screencolors.xojo\_binary\_project](http://match-software.com/xojo/Screencolors.xojo_binary_project)

To make it work within the timer Action event, I made some variables window properties, but I left the older code as comments.[/quote]

I think your link is broken, I think is not zipped !

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [August 22, 2014, 11:41pm UTC](https://forum.xojo.com/t/capture-rgb-values/18779/12 "2014-08-22T23:41:29Z")

</div>

> [@123816:@Paulo Vargas](#):
>
> I think your link is broken, I think is not zipped !

No, it is not zipped. Just download, and open it. I just verified it.

---

<div class="post-metadata">

**Author:** ![Paulo\_Vargas](https://forum.xojo.com/user_avatar/forum.xojo.com/paulo_vargas/32/232_2.png) [@Paulo\_Vargas](https://forum.xojo.com/u/Paulo_Vargas)\
**Post date:** [August 22, 2014, 11:42pm UTC](https://forum.xojo.com/t/capture-rgb-values/18779/13 "2014-08-22T23:42:35Z")

</div>

For me the download does not happen, only appears codes in the browser 😉

---

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [August 22, 2014, 11:52pm UTC](https://forum.xojo.com/t/capture-rgb-values/18779/14 "2014-08-22T23:52:02Z")

</div>

Paulo - simply right-click and select Download linked File As…

---

<div class="post-metadata">

**Author:** ![Paulo\_Vargas](https://forum.xojo.com/user_avatar/forum.xojo.com/paulo_vargas/32/232_2.png) [@Paulo\_Vargas](https://forum.xojo.com/u/Paulo_Vargas)\
**Post date:** [August 22, 2014, 11:56pm UTC](https://forum.xojo.com/t/capture-rgb-values/18779/15 "2014-08-22T23:56:18Z")

</div>

Tanks Richard Summers, worked perfectly !

---

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [August 23, 2014, 12:03am UTC](https://forum.xojo.com/t/capture-rgb-values/18779/16 "2014-08-23T00:03:52Z")

</div>

Michel,  
Is there any way to stop the timer when the user clicks on the desired colour (outside of the app - such as on the desktop)?

If the user clicks on the desktop for example - the MouseDown event will obviously not fire (as expected).

Thank you Michel.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [August 23, 2014, 12:51am UTC](https://forum.xojo.com/t/capture-rgb-values/18779/18 "2014-08-23T00:51:42Z")

</div>

[quote=123829:@Richard Summers]Michel,  
Is there any way to stop the timer when the user clicks on the desired colour (outside of the app - such as on the desktop)?

If the user clicks on the desktop for example - the MouseDown event will obviously not fire (as expected).[/quote]

There is no way to catch the mouseDown out of the application windows. The best replacement is to use the keyboard in lieu of the mouse button. For instance, you could use the keydown event and any key will replace the mouse click.

Another trick is to display a full screen window with the captured screen as backdrop before the app window. So you can then click on what will be the first window, it will register. But then the user will not be able to activate anything on the screen, besides the app menu and the dock. It becomes sort of a super modal mode that is not quite nice to the user.

---

<div class="post-metadata">

**Author:** ![Paulo\_Vargas](https://forum.xojo.com/user_avatar/forum.xojo.com/paulo_vargas/32/232_2.png) [@Paulo\_Vargas](https://forum.xojo.com/u/Paulo_Vargas)\
**Post date:** [August 23, 2014, 1:21am UTC](https://forum.xojo.com/t/capture-rgb-values/18779/19 "2014-08-23T01:21:28Z")

</div>

[quote=123829:@Richard Summers]Michel,  
Is there any way to stop the timer when the user clicks on the desired colour (outside of the app - such as on the desktop)?

If the user clicks on the desktop for example - the MouseDown event will obviously not fire (as expected).

Thank you Michel.[/quote]

Richard and Michael yes exist one way, put this code in Timer

[code] if System.MouseDown=true then

```
me.mode=0

```

end If[/code]

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [August 23, 2014, 9:21am UTC](https://forum.xojo.com/t/capture-rgb-values/18779/20 "2014-08-23T09:21:13Z")

</div>

The issue to click out of the application is that even the timer stops, as the app is deactivated. So the code above simply never executes.

To answer Richard concern of stopping the timer if the user clicks outside, Timer1.stop in deactivate will do nicely.

I inferred what he wanted to do was to get the color on the screen out of the app area upon click instead of continuously, hence my reply.

There is another way to have an app that allows clicking out of the app without deactivating it. The code comes from Axel Schneider he posted in the drag border thread. Put this in the Window Deactivate event :

` declare function NSClassFromString lib "Cocoa" ( inName as CFStringRef ) as Ptr
  declare function sharedApplication lib "Cocoa" selector "sharedApplication" ( classRef as Ptr ) as Ptr
  Dim myApplication as Ptr = sharedApplication( NSClassFromString( "NSApplication" ) )
  declare sub activateIgnoringOtherApps lib "Cocoa" selector "activateIgnoringOtherApps:" ( appRef as Ptr, flag as boolean )
  activateIgnoringOtherApps( myApplication, True )`

This way when the window is deactivated, it immediately comes back to front. This is also the answer to an old post of Richard’s [https://forum.xojo.com/13260-force-z-order](https://forum.xojo.com/13260-force-z-order) where he wanted to force his app on top of all others.

Then to get the color upon click the timer must monitor System.MouseDown to get the color.

It has the same effect as the “super modal” trick with a full screen window showing the screen capture : the only way to activate another app is to inhibit the declare. This can be done by simply quitting the app, or using a long click code, or by holding a key, or setting a menu option. Compared to the fullscreen/backdrop method, this one has the inconvenient to flicker when the mouse is clicked outside of the app’s window. It does allow clicking on buttons and launching apps, though. But I posted it because it can be used in many other places.

---

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [August 23, 2014, 10:40am UTC](https://forum.xojo.com/t/capture-rgb-values/18779/21 "2014-08-23T10:40:37Z")

</div>

Thanks Michel - I will stick with the press enter version 🙂

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [August 23, 2014, 10:58am UTC](https://forum.xojo.com/t/capture-rgb-values/18779/22 "2014-08-23T10:58:38Z")

</div>

> [@123908:@Richard Summers](#):
>
> Thanks Michel - I will stick with the press enter version 🙂

Keep it simple 😉 Space bar maybe easier to locate for the user.

[Next page](https://forum.xojo.com/t/capture-rgb-values/18779.md?page=2)
