Loading...


bookmark - Get Pixel's Color

Get Pixel's Color

 
 Discussion by p_a with 10 Replies.
 Last Update: January 9, 2012, 5:01 pm ( View Rated (1) )
 
bookmark - Get Pixel's Color  
Quickly Post to Get Pixel's Color  w/o signup Share Info about Get Pixel's Color  using Facebook, Twitter etc. email your friend about Get Pixel's Color Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

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?











   Sun Oct 9, 2005    Reply         

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.







   Sun Oct 9, 2005    Reply         

Okay, considering Javascript is not strong enough, can VBscript do the task?

   Sun Oct 9, 2005    Reply         


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.

   Mon Oct 10, 2005    Reply         

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.

   Mon Oct 10, 2005    Reply         

I have got very good sample for you. have a lokk http://www.cs.duke.edu/courses/cps004/fall.../RGBCanvas.html and use in you script. that is gonna help you.

   Tue Oct 18, 2005    Reply         


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!

   Thu Jan 5, 2006    Reply         

Is it possible to use a java applet to find out the color of a pixel on a web page?

   Thu Mar 9, 2006    Reply         

QUOTE (Aparna)


Is it possible to use a java applet to find out the color of a pixel on a web page?

Link: view Post: 234834

Did you read two posts up?
Maybe three...

   Thu Mar 9, 2006    Reply         

It's too bad that the RGBCanvas != the user's screen, isn't it?

   Fri Mar 10, 2006    Reply         

QUOTE (p_a)


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?

Link: view Post: 193702







[font=Arial,]Merging various references found here in StackOverflow and in other sites, I did so using javascript and JQuery:[/font]
<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, B){
if (r > 255 || g > 255 || b > 255)
throw "Invalid color component";
return ((r << 16) | (g << 8) | B).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(pcolor=#800000]0[/color, pcolor=#800000]1[/color, pcolor=#800000]2[/color)).slice(-6);
alert("HEX: " + hex);
});
</script>
<img src="photo_apple.jpg"/>
</body>
</html>

[font=Arial,]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).[/font]

   Mon Jan 9, 2012    Reply         

Quickly Post to Get Pixel's Color  w/o signup Share Info about Get Pixel's Color  using Facebook, Twitter etc. email your friend about Get Pixel's Color Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

Similar Topics:

A Really Cool Online Color Picker ...

Hi - Sometimes when you're designing a website (or getting ready to paint your house!) you need to have color samples which you can mix and match, to get an idea of how things will look. There are several interactive websites online which help you choose a set of co ...more

   11-Nov-2008    Reply         

Changing Eye Color In Paint Shop Pr...

Okay so I have been contemplating color contacts for a while (the plano kind of course, having 20/20 vision roxs!) and wanted to try on colors with out paying for the doctor's visit. So I used paint shop pro. The tools in paint shop pro not only vary from those in photoshop, but I think th ...more

   05-Jan-2009    Reply         

How Do I Change Table Border Color ...

Hi all, I am making a website and want to change a table's border color. I am using the regular code of: bordercolor="#000000", and it just stays white, any help would be appreciated. The link to the test page is here[/ ...more

   31-May-2010    Reply         

Can't Assign Value    Can't Assign Value (1) (2) Whats The Classpath (for The Packages) On Trap17 I don't want to recompile my classes 20x  Whats The Classpath (for The Packages) On Trap17 I don't want to recompile my classes 20x