Skip to content

Instantly share code, notes, and snippets.

@ynonp
Created November 29, 2012 12:19
Show Gist options
  • Save ynonp/4168631 to your computer and use it in GitHub Desktop.
Save ynonp/4168631 to your computer and use it in GitHub Desktop.
came
<!DOCTYPE html>
<html>
<head>
<title>Camera Demo</title>
<meta name="viewport" content="width=device-width" />
</head>
<body>
<input type="file" accept="image/*" id="imageLoader"/>
<canvas id="imageCanvas" width=300 height="300"></canvas>
<script>
var imageLoader = document.getElementById('imageLoader');
imageLoader.addEventListener('change', handleImage, false);
var canvas = document.getElementById('imageCanvas');
var ctx = canvas.getContext('2d');
function handleImage(e) {
var reader = new FileReader();
reader.onload = function(event){
var img = new Image();
img.onload = function(){
ctx.drawImage(img,0,0);
}
img.src = event.target.result;
}
reader.readAsDataURL(e.target.files[0]);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment