|
|
|
ดูโค้ดช่วยทีค่ะ ต้องการกำหนดบางช่วงของสีบนรูปภาพเป็นค่าตัวเลข แต่มันไม่ออก |
|
|
|
|
|
|
|
ช่วยดูโค้ดให้ที
ค่าz ไม่ขึ้นค่ะ
เข้าใจตรงไหนผิด ช่วยทีนะคะ
มือใหม่มากค่ะ ไม่เข้าใจ javascriptเลยย ./\.
งมมาหลายเดือนแล้วค่ะ TT
Code
1.
2.
Code (JavaScript)
<head>
<center><canvas id="myCanvas" width="90" height="500" style="border:1px solid #c3c3c3;">
Your browser does not support the canvas element.
</canvas><br>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<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 ='imgR/shade.gif';
context.drawImage(img, 0, 0);
var color = new Color();
color.rgb = (255,255,255);
};
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 rgbToH(r, g, b){
if(r>255 || g >255|| b >255)
throw "Invalid color component";
return ((r << 16) | (g << 8) | b).toString(16);
}
function rgbToZ(rbg){
var z;
var r;
var g;
var b;
for(r= 0;r<=255;r++){
for(g=0;g<=255;g++){
for(b=0;b<=255;b++){
if(r>8 || g >15 || 191> b ){
z = "-10";
return z;
}else if(r>8 ||( 16> g)&&(g >31)|| (175>b )&&(b>192)){
z = "-7.5";
return z;
} else if(r>8 || (32>g)&& (g>47)||(176>b)&&( b>159)){
z = "-5";
return z;
}else if(r>8 ||( 48> g)&&(g >63)||( 160> b)&&(b >143)){
z = "-3";
return z;
} else if(r>8 ||( 64> g)&&(g >79)||( 144> b)&&( b>133)){
z = "-0.5";
return z;
}
}
}
}
}
$('#myCanvas').mousedown(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"+rgbToH(p[0],p[1],p[2])).slice(-6);
var zd = rgbToZ(z);
document.getElementById("z").innerHTML = zd;
document.getElementById("hex").innerHTML = hex;
document.getElementById("coordinate").innerHTML = coordinate;
});
</script>
</head>
<body>
hex:<span id="hex"></span>
z:<span id="z"></span>
coordinate:<span id="coordinate"></span>
<br><br></center>
<img src="imgR/shade.gif" width="50" height="200" >
Tag : JavaScript, Ajax, jQuery
|
ประวัติการแก้ไข 2015-07-05 02:11:50 2015-07-05 12:52:15 2015-07-05 12:53:19 2015-07-05 14:42:20 2015-07-06 03:50:49
|
|
|
|
|
Date :
2015-07-05 02:00:01 |
By :
tata |
View :
1208 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
กระทู้นี้ได้แล้วหรือยังครับ
|
|
|
|
|
Date :
2015-07-11 10:16:43 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|