Skip to content

Instantly share code, notes, and snippets.

@nishinoshake
Created February 2, 2016 15:37
Show Gist options
  • Save nishinoshake/b98cf7e9a3d228cba525 to your computer and use it in GitHub Desktop.
Save nishinoshake/b98cf7e9a3d228cba525 to your computer and use it in GitHub Desktop.
canvasで画像を使う
var canvas = document.getElementById('canvas'),
ctx = canvas.getContext('2d'),
image = new Image();
canvas.setAttribute('width', window.innerWidth);
canvas.setAttribute('height', window.innerHeight);
image.src = 'sample.jpg';
image.addEventListener('load', function() {
// load完了しないと描画できない
ctx.drawImage(image, 0, 0);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment