p_a 0 Report post Posted October 9, 2005 How to get a pixel's color from any certain pixel at the screen, using Javascript, dhtml, any client-side scripting language?For example how to get pixel's color for 10,10 pixel? Share this post Link to post Share on other sites
beeseven 0 Report post Posted October 10, 2005 My friend made a version of MSPaint in Java for a project in our Computer Science class, but couldn't make a filler because we determined that there was no plausible way to determine a pixel's color. That, the fact that JavaScript is generally weaker than Java, and the fact that pixels on the client's machine would probably not be on the page where the script is contained would lead me to believe that it's not possible. JS always manages to surprise me, though, so I guess you could keep looking. Just don't get your hopes up. Share this post Link to post Share on other sites
p_a 0 Report post Posted October 10, 2005 Okay, considering Javascript is not strong enough, can VBscript do the task? Share this post Link to post Share on other sites
cse-icons 0 Report post Posted October 10, 2005 hi p_a,I dont think either javascript/vbscript have such a feature incorporated into them. But Java would surely have that feature, which beeseven says to not having found. Even C/C++ have the feature to get the color of the pixed under the mouse cursor. So I do not think that Java would do without such a feature, esp Swing.Cheers. Share this post Link to post Share on other sites
p_a 0 Report post Posted October 10, 2005 Thanks all! I still believe that there should be a way to get pixel's color using client side scripting like Javascript or VBScript. In my web application I even do not need to have the color under mouse pointer, but just the color at certain position, like 10,10 as I mentioned above. I do not know if PHP or Perl can do it (both are server scripting languages) but I am sure that Java can do it. The only problem is that I really want to avoid Java, not because it is bad, but because of - I already have PHP+Javascript in my application, and Java is sometimes slow to start itself into memory, especially on older PCs. I had really bad experience with JSP, I have even kind of strange anxiety using JSP, cause when I transfered my applications from JSP to PHP I got them work much, much faster and more reliable. Somebody would say I should just make better JSP setings on my web server, but, with PHP everything worked amazingly smooth immidiately.I hope that I'll find a way to get pixel color without using Java. Share this post Link to post Share on other sites
dul 0 Report post Posted October 19, 2005 I have got very good sample for you. have a lokk http://forums.xisto.com/no_longer_exists/ and use in you script. that is gonna help you. Share this post Link to post Share on other sites
kaylanicole 0 Report post Posted January 5, 2006 well what i do when i'm trying to get a pixel's color is i press the print screen button on the keyboard, open up photoshop, paste it, zoom in to where the pixels are visible, and use the eyedropper tool to click on the pixel i want the color of. the color goes to foreground color box so click on that twice. a color picker box comes up and at the bottom of it is # beside a textbox. in that textbox is the code of that color so copy and paste that to whereever you need it and there ya go! Share this post Link to post Share on other sites
Aparna 0 Report post Posted March 9, 2006 Is it possible to use a java applet to find out the color of a pixel on a web page? Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted March 9, 2006 Is it possible to use a java applet to find out the color of a pixel on a web page?Did you read two posts up?Maybe three... Share this post Link to post Share on other sites
beeseven 0 Report post Posted March 11, 2006 It's too bad that the RGBCanvas != the user's screen, isn't it? Share this post Link to post Share on other sites
iGuest 3 Report post Posted January 10, 2012 How to get a pixel's color from any certain pixel at the screen, using Javascript, dhtml, any client-side scripting language? For example how to get pixel's color for 10,10 pixel? Merging various references found here in StackOverflow and in other sites, I did so using javascript and JQuery: <html> <body> <canvas id="myCanvas" width="400" height="400" style="border:1px solid #c3c3c3;"> Your browser does not support the canvas element. </canvas> <script src="jquery.js"></script> <script type="text/javascript"> window.onload = function(){ var canvas = document.getElementById('myCanvas'); var context = canvas.getContext('2d'); var img = new Image(); img.src = 'photo_apple.jpg'; context.drawImage(img, 0, 0); }; function findPos(obj){ var current_left = 0, current_top = 0; if (obj.offsetParent){ do{ current_left += obj.offsetLeft; current_top += obj.offsetTop; }while(obj = obj.offsetParent); return {x: current_left, y: current_top}; } return undefined; } function rgbToHex(r, g, { if (r > 255 || g > 255 || b > 255) throw "Invalid color component"; return ((r << 16) | (g << 8) | .toString(16); } $('#myCanvas').click(function(e){ var position = findPos(this); var x = e.pageX - position.x; var y = e.pageY - position.y; var coordinate = "x=" + x + ", y=" + y; var canvas = this.getContext('2d'); var p = canvas.getImageData(x, y, 1, 1).data; var hex = "#" + ("000000" + rgbToHex(p[0], p[1], p[2])).slice(-6); alert("HEX: " + hex); }); </script> <img src="photo_apple.jpg"/> </body> </html> This is my complete solution.. Here I only used canvas and one image, but if you need to use <map>over the image, it's possible too. I hope I have helped, any problems, please contact me at my e-mail (ebfjunior@gmail.com). Share this post Link to post Share on other sites