Read pixel color from screen for a given coordinate.

283 views
Skip to first unread message

solewalker

unread,
Oct 3, 2014, 9:30:46 AM10/3/14
to haxef...@googlegroups.com
I wanted to read pixel color either RGB or Hex from the screen for a point inside game window. This could be either a mouse coordinate or a FlxPoint. I searched for a while but could not found anything on this topic. I am not talking about reading pixels off the screen for making a bitmap or sprite. So I need color for one pixel not a given rect inside the screen. Like sorta this,

var pixColor = ReadPixelFromScreen(x, y);  // x, y is a coordinate on the screen

Gama11

unread,
Oct 3, 2014, 11:02:17 AM10/3/14
to haxef...@googlegroups.com
On Flash or HTML5, you can access the camera buffer for this:

FlxG.camera.buffer.getPixel(x, y);

That is, if you don't have any additional cameras / messed with the camera positioning.

solewalker

unread,
Oct 3, 2014, 11:46:45 AM10/3/14
to haxef...@googlegroups.com
So it does not work on native? I am yet to try the code, as I am not at my home right now.

Gama11

unread,
Oct 3, 2014, 12:06:23 PM10/3/14
to haxef...@googlegroups.com
Yep, no camera buffer in FLX_RENDER_TILE mode. There's no reliable way to get a BitmapData with the screen contents on native I know of.

solewalker

unread,
Oct 3, 2014, 2:52:43 PM10/3/14
to haxef...@googlegroups.com
This is more of a openfl thing, I see they have implemented the function in development version of lime, so I would try to use dev lime, if it does not break flixel or other things.

Gama11

unread,
Oct 3, 2014, 3:11:19 PM10/3/14
to haxef...@googlegroups.com
No, it's not. Which function do you mean? getPixel()? That's always been part of OpenFL's BitmapData, the problem is that FlxG.camera has no buffer BitmapData on native targets.

solewalker

unread,
Oct 3, 2014, 3:40:41 PM10/3/14
to
I am talking about GL.readPixels http://www.openfl.org/forums/#!/programming:how-to-use-glreadpixels-

This is the way I used to read pixel in pre-shader opengl  or without using any shader code.
Reply all
Reply to author
Forward
0 new messages