【问题标题】:input type="file" not populating canvas on android browser输入类型=“文件”没有在Android浏览器上填充画布
【发布时间】: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


    【解决方案1】:

    升级到最新版本的andriod似乎可以解决这个问题!

    【讨论】:

      猜你喜欢
      • 2021-02-25
      • 2013-02-02
      • 2012-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-24
      • 2013-11-04
      • 2014-06-03
      相关资源
      最近更新 更多