Capture RGB Values

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.

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.

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

Just on MAC !

Here is an example project I put together for a previous thread:
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.

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

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 ?

[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
http://osxdaily.com/2010/06/09/screen-capture-in-mac-os-x/[/quote]

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!

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 :wink:

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=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 :wink:

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 !

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

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

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

Tanks Richard Summers, worked perfectly !

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=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.

[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]

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 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.

Thanks Michel - I will stick with the press enter version :slight_smile:

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