使用jQuery和Javascript打开IOS相机应用程序并将其存储为变量

Nic*_*oub 8 javascript jquery

有没有可能我可以使用jQuery和Javascript,这样我就可以在IOS上打开相机应用程序,拍照,然后将该图像保存到变量中,以便我可以将其上传到解析中?

我不喜欢使用它,因为你无法控制图像.

<input id = "Input" type="file" accept="image/*" capture="camera">
Run Code Online (Sandbox Code Playgroud)

谢谢

Mor*_*sen 2

您可以将 File API 与生成的、不可见的输入 [type="file"] 一起使用,这将为您留下一个 File 对象,然后您可以将其用作二进制文件,或者如下面的示例所示,用作 base64 url ,然后您可以将其传递到服务器。

var btn = document.getElementById('upload-image'),
  uploader = document.createElement('input'),
  image = document.getElementById('img-result');

uploader.type = 'file';

btn.onclick = function() {
  uploader.click();
}

uploader.onchange = function() {
  var reader = new FileReader();
  reader.onload = function(evt) {
    image.src = evt.target.result;
  }
  reader.readAsDataURL(uploader.files[0]);
}
Run Code Online (Sandbox Code Playgroud)
<button id="upload-image">Select Image</button>
<img id="img-result" style="max-width: 200px;" />
Run Code Online (Sandbox Code Playgroud)