我試圖在座標點x,y繪製圖像,x和y位於圖像的中心。用x,y繪製圖像與圖像的中心點有關嗎?
我有這樣的代碼,我發現前面的旋轉圖像:
function drawImageRot(img,x,y,width,height,deg) {
//Convert degrees to radian
var rad = deg * Math.PI/180;
//Set the origin to the center of the image
context.translate(x + width/2, y + height/2);
//Rotate the canvas around the origin
context.rotate(rad);
//draw the image
context.drawImage(img, width/2 * (-1), height/2 * (-1), width, height);
//reset the canvas
context.rotate(rad * (-1));
context.translate((x + width/2) * (-1), (y + height/2) * (-1));
}
但是它似乎借鑑下方和右側的圖像?即x,y座標是否與圖像的左上角相關?
是的。在大多數框架中,(0,0)座標是容器的左上角。這對於圖像以及窗體中的控件都是如此。 – Renan 2013-05-14 14:32:58
我已經添加了幾個標籤來獲得更多的知名度 - 如果我猜錯了,請更正! – 2013-05-14 14:33:11