Color of a pixel

Get help using Construct 2

Post » Sun Jun 28, 2015 1:15 pm

Is there any method or plugin for picking the color of a pixel in Construct 2 like photoshop ar any other drawing app?
I want to just get the RGB value of a given pixel (like x,y). If anyone knows, please help me.
B
4
Posts: 15
Reputation: 234

Post » Sun Jun 28, 2015 1:36 pm

Well there is the color picker tool in the image editor.
If you mean at runtime, C2 packs the rgb() system expression.

There is the third-part plugin named "Canvas" that also seems to have a rgbat() expression that might work, but IIRC it may have issues with WebGL.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
289
S
112
G
94
Posts: 7,333
Reputation: 69,293

Post » Sun Jun 28, 2015 2:27 pm

It is possible but usually inadvisable, unless it is something like the picker. Why do you want to do this ?
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328

Post » Sun Jun 28, 2015 5:18 pm

I just want to get RGB value at any (x,y) position at C2 runtime
B
4
Posts: 15
Reputation: 234

Post » Sun Jun 28, 2015 9:05 pm

That's going to involve hacking WebGL and/or Canvas. There's probably a better way to do it.
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328

Post » Mon Jun 29, 2015 5:05 am

How??? Please describe..
B
4
Posts: 15
Reputation: 234

Post » Mon Jun 29, 2015 3:30 pm

This expression will get the red of the pixel under the mouse:
Code: Select all
Browser.ExecJS("var canvas=document.getElementById('c2canvas');
var ctx=canvas.getContext('2d');
var pixel=ctx.getImageData("&int(LayerToCanvasX(0, mouse.x, mouse.y))&","&int(LayerToCanvasY(0, mouse.x, mouse.y))&",1,1);
pixel.data[0];")


You can get the other color components by changing the 0 in
pixel.data[0]
to
1 for green
2 for blue
3 for alpha
B
92
S
32
G
106
Posts: 5,273
Reputation: 69,457


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 14 guests