Not supported in all browser (IE and Opera AFAIK) but you could get a data URI using the File API
function draw() {
var ctx = document.getElementById('canvas').getContext('2d')
, img = new Image()
, f = document.getElementById("uploadimage").files[0]
, url = window.URL || window.webkitURL
, src = url.createObjectURL(f);
img.src = src;
img.onload = function(){
ctx.drawImage(img,0,0);
url.revokeObjectURL(src);
}
}
<input type='file' name='img' size='65' id='uploadimage' />
I added a fiddle here as an example.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…