방금 자바 스크립트로 시작했고 이미지 검색 갤러리를 코딩하려고합니다. xml 데이터베이스 파일로 이미지 원본을 가져옵니다.자바 스크립트를 사용하여 캔버스에 축소판 이미지 만들기
는 내가 루프에 대한 이미지의 소스 물마루 들어가 있고, 그때 캔버스에 각각의 이미지를 그립니다. 하지만 내가하고 싶은 것은 다른 창에서 실제 크기의 이미지를 보여주고 싶은 이미지를 클릭 할 때입니다.
은 어떻게 (바람직하게는 단지 자바 스크립트를 사용하여) 그렇게합니까? Heres는
코드의 부분 : 사전에
//goes trough the xml database searching for the image
for (var p = 0 ; p < xmlDoc.firstChild.childNodes.length ; p ++)
{
if (xmlDoc.firstChild.childNodes[p].nodeName == 'path')
{
document.getElementById("results_ID").innerHTML += xmlDoc.firstChild.childNodes[p].textContent+"<br />";
var src = xmlDoc.firstChild.childNodes[p].textContent;
//fill the array with the images
arrImg.push(src);
}
}
}
}
}
}
//resize and draw the images founded
resizeCanvas(arrImg.length);
for(var i = 0; i < arrImg.length; i++)
{
drawImg(arrImg[i]);
}
}
//function do draw the images
function drawImg(src)
{
var img = new Image();
img.onload = function()
{
if (x > ctx.canvas.width)
{
y = y + 310;
x = 0;
}
img.width = 300;
img.height = 300;
ctx.drawImage(img, x, y, img.width, img.height); //(0,0)
x = x + 310;
};
img.src = src;
}
//function to resize the canvas by the number of images found
function resizeCanvas(nImages)
{
var height = (nImages/4);
ctx.canvas.height = Math.round(height) * 310;
alert(ctx.canvas.height);
};
감사합니다.
가 바로 보이는 것, 그러나 내가 imageRegions 배열 안의 값을 검사 할 때 영역을 저장하려 할 때 그것은 모두 정의되지 않았습니다 –
@ Cap.Alvez이 작업을 보여주기 위해 데모로 내 대답을 업데이트했습니다. imageRegions는 어디에서 정의합니까? – K3N
""undifined "문제를 이미 해결했습니다. 나는 잘못된 장소에 값을 저장하고 있었다. 하지만 지금 나는 올바른 값을 저장하고있다. (나는 이미 체크했다) 문제는 if (x> rx && x