0

マウスで描画できるキャンバスがあります.ボタンをクリックすると、描画をキャプチャしてキャンバスのすぐ下に追加し、前のものをクリアして新しいものを描画する必要があります..最初のキャンバスは静的でなければなりません他のものは、私が描いた絵で動的に作成する必要があります..どうすれば誰でも助けてくれますか

ここにjsfiddleがあります http://jsfiddle.net/dQppK/378/

var canvas = document.getElementById("canvas"),
ctx = canvas.getContext("2d"),
painting = false,
lastX = 0,
lastY = 0;
4

2 に答える 2

0

これは、私が作成したライブラリの一部であり、キャンバスに関するいくつかのことを容易にするために使用します。他の機能が役立つ可能性がある場合に備えて、githubに置いただけです。後でreadmeを作成する必要があります...

https://github.com/gamealchemist/CanvasLib

名前空間を削除すると、canvas を挿入するコードは次のようになります。

// insert a canvas on top of the current document.
// If width, height are not provided, use all document width / height
// width / height unit is Css pixel.
// returns the canvas.
insertMainCanvas = function insertMainCanvas (_w,_h) {
   if (_w==undefined) { _w = document.documentElement.clientWidth & (~3)  ; }
   if (_h==undefined) { _h = document.documentElement.clientHeight & (~3) ; }
   var mainCanvas = ga.CanvasLib.createCanvas(_w,_h);
   if ( !document.body ) { 
          var aNewBodyElement = document.createElement("body"); 
              document.body = aNewBodyElement; 
   };
   document.body.appendChild(mainCanvas);
   return mainCanvas;
}
于 2013-08-08T00:10:09.403 に答える