Rishi
Rishi

Reputation: 1349

How can we get the background colour of a gradient image at particular point in Javascript?

I have a gradient image and I want to get the background color at all positions where I move my mouse i.e. at a particular positions.

I can get the position of mouse so now I have to get the color at that position.

So please Guide me for this problem

Upvotes: 1

Views: 189

Answers (1)

Muayyad Alsadi
Muayyad Alsadi

Reputation: 1593

if you made your image as a canvas named ctx then

var imgd = ctx.getImageData(x, y, 1, 1);
var colorhex=RGBtoHex(imgd.data[0],imgd.data[1],imgd.data[2]);

here is an example http://nerderg.com/Canvas+Color+Picker

Upvotes: 3

Related Questions