use*_*555 17 html javascript jquery
我正在尝试制作一个javascript图像颜色选择器.可以在画布中打开本地图像,而无需将其上传到服务器?
function draw() {
var ctx = document.getElementById('canvas').getContext('2d');
var img = new Image();
img.onload = function(){
ctx.drawImage(img,0,0);
}
img.src = $('#uploadimage').val();
}
<input type='file' name='img' size='65' id='uploadimage' />
Run Code Online (Sandbox Code Playgroud)
Phi*_*ons 34
并非所有浏览器(IE和Opera AFAIK)都支持,但您可以使用File API获取数据URI
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' />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14780 次 |
| 最近记录: |