|
|
Get Pixel's Color | ||
Discussion by p_a with 10 Replies.
Last Update: January 9, 2012, 5:01 pm ( View Rated (1) ) | |||
![]() |
|
|
For example how to get pixel's color for 10,10 pixel?
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.
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.
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...
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,
if (r > 255 || g > 255 || b > 255)
throw "Invalid color component";
return ((r << 16) | (g << 8) |
}
$('#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]
Similar Topics:
A Really Cool Online Color Picker ...
Changing Eye Color In Paint Shop Pr...
How Do I Change Table Border Color ...
Can't Assign Value (1)
|
(2) Whats The Classpath (for The Packages) On Trap17 I don't want to recompile my classes 20x
|
Loading...
HOME 






