2014-04-23 5 views
0

javascript/jquery로 xy 픽셀의 색상을 얻으려고합니다. 따라서 인터넷 검색을 캔버스에서 수행 할 수 있음을 알았습니다.픽셀의 색상을 얻으십시오.

var canvas = $("<canvas>"); //Create the canvas element 

//Create a layer which overlaps the whole window 
canvas.css({ position: "fixed", top: "0", left: "0", 
    width: "100%", height: "100%", "z-index": 9001 
}); 

//Add an event listener to the canvas element 
canvas.click(function (ev) { 
    var x = ev.pageX, y = ev.pageY; 
    var canvas = this.getContext("2d"); 
    canvas.drawWindow(window, x, y, 1, 1, "transparent"); 
    var data = canvas.getImageData(0, 0, 1, 1).data; 
    var hex = rgb2hex(data[0], data[1], data[2]); 
    alert(hex); 
    $(this).remove(); 
}); 

그러나 작동하지 않습니다 (firefox에서 작동하지 않음, 크롬에서도 작동하지 않음).
어떤 아이디어?

+0

실제로 DOM에 canvas 요소가 지정 되었습니까? '$ ('body'). append (canvas); ' – gondo

+1

http://stackoverflow.com/questions/8751020/how-to-get-a-pixels-xy-coordinate-color-from-an-image – Bharadwaj

+0

@ Bharadwaj : 작동하지 않는 것을보십시오 http://jsfiddle.net/9SEMf/938/ –

답변

관련 문제