【发布时间】:2015-03-13 17:48:04
【问题描述】:
我尝试使用具有用户个人资料页面的 html5 构建 Web 应用程序,但在 Android 浏览器上测试时遇到了 input type="file" 的问题。选择后,我可以选择打开相机或画廊,选择文件时,它会填充文件字段,但我无法让文件填充画布。这在 ios 和 firefox 上完美运行,在 Android 上运行 chrome。
这里是html代码:
<canvas id="canvas" width="160" height="120" style="border:1px solid #000000;"></canvas>
<input type="file" capture="camera" accept="image/*" id="takePictureField" onchange="picChange(event)">
还有 JavaScript:
函数 picChange(evt) { var fileInput = evt.target.files;
if(fileInput.length>0)
{
var windowURL = window.URL || window.webkitURL;
var picURL = windowURL.createObjectURL(fileInput[0]);
var photoCanvas = document.getElementById("canvas");
var ctx = photoCanvas.getContext("2d");
var photo = new Image();
photo.onload = function()
{
ctx.drawImage(photo, 0, 0, 160, 120);
};
photo.src = picURL;
windowURL.revokeObjectURL(picURL);
}
}
谁能看到我做错了什么?我是否需要在 windowURL 中添加一些内容以便 Android 可以识别它?任何帮助将不胜感激,因为这真的开始困扰我了!
【问题讨论】:
标签: javascript android html canvas input-type-file