Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [Source] AGK V1 + V2 Point Command (Color Extractor)

Author
Message
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 15th Sep 2014 03:33 Edited at: 15th Sep 2014 03:34
I just shared this code in the V2 Development Blog thread in response to Santman asking if such a feature existed, but figure it could be useful to anyone who isn't monitoring that thread as the topic has come up in the past.

There isn't a native command for this capability (Lee originally said it was omitted due to mobile performance reasons when AppGameKit was young) but with memblocks it becomes easy to integrate such functionality yourself. Here is a function that does just that. It is fast enough to be called each frame and run full speed on the devices I tested, but could slow down depending on your requirements (i.e., if you need to call it for many different coords each frame). Essentially it grabs an image at the specified coordinates, converts it to a memblock and then extracts the color value and returns it to you for further processing.

Instructions: Copy the functions below to your app.

Usage: colorVal = Point(x, y, returnType)

x, y: The coordinate that you wish to extract the color value from.

returnType: 0 = raw integer value, 1/2/3/4 = Red/Green/Blue/Alpha component value

If using '0' as the return type to get the full RGBA value, you can then extract the RGBA components manually using the GetColorR[G/B/A]() functions provided. AppGameKit V2 includes GetColorRed[Green/Blue] natively as well, but these functions I've included ensure compatibility with V1 and support easy alpha extraction.

Attached also is a full working example.

Attachments

Login to view attachments
mr_d
DBPro Tool Maker
17
Years of Service
User Offline
Joined: 26th Mar 2007
Location: Somewhere In Australia
Posted: 16th Sep 2014 14:03
nice, and thanks for sharing.
do you know if it would be possible (and if so how difficult if so) it would be to use this to do a sort of face recognition on a photo?

Login to post a reply

Server time is: 2024-04-20 12:56:07
Your offset time is: 2024-04-20 12:56:07