我有一個寬度爲400和高度爲400的畫布和寬度爲3392和高度爲232的圖像。 我想剪裁此圖像的第一個400像素並將其繪製在畫布內 我該怎麼做?在畫布內繪製圖像的一部分
$(document).ready(function() {
var ctx = $("#MyCanvas")[0].getContext("2d"); // the "context" of the canvas that will be used (2D or 3D)
var cw = 400; // width of the rectangular area
var ch = 400; // height of the rectangular area
var FieldImg= new Image(); // Image to be loaded and drawn on canvas
var ImgNumb = 12; // Number of images that make up the movement
var Fps = 30;
init();
function init() {
FieldImg.src = "images/Spritebackground.png";
ctx.drawImage(FieldImg, 0, 0, 400, 400, 0, 0, 400, 400);
}
});
ctx.drawImage(FieldImg, 0, 0, 400, 400, 0, 0, 400, 400);
此行不工作? 這是我的jsfiddle:http://jsfiddle.net/seekpunk/3uhgN/
究竟你是什麼意思與 「不工作」?它做什麼呢? – Philipp
請看我的jsfiddle – Sora