通过浏览器访问相机
我们正在为移动设备创建一个 HTML5 网站,需要通过网络浏览器访问相机,而无需成为本机应用程序。我们在 iOS 中无法实现此功能。有人知道这个问题的解决方案吗?
We are creating an HTML5 website for mobile and need to get camera access through the web browser without being a native app. We are having trouble making this work in iOS. Is anyone aware of a solution for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以尝试这个:
但它必须是 iOS 6+ 才能工作。这将为您提供一个很好的对话框,供您选择拍照或从相册上传一张照片,即
>示例可以在这里找到:
不使用 PhoneGap 捕获相机/图片数据
You could try this:
but it has to be iOS 6+ to work. That will give you a nice dialogue for you to choose either to take a picture or to upload one from your album i.e.
An example can be found here:
Capturing camera/picture data without PhoneGap
截至 2015 年,它现在可以正常工作。
这将要求用户上传任何文件。在 iOS 8.x 上,这可以是相机视频、相机照片或照片库中的照片/视频。
与上述相同,但仅限上传来自相机或图库的照片,不得上传视频。
As of 2015, it now just works.
This will ask user for the upload of any file. On iOS 8.x this can be a camera video, camera photo, or a photo/video from Photo Library.
This is as above, but limits the uploads to photos only from camera or library, no videos.
在 iOS6 中,Apple 通过
标签支持此功能。我在 Apple 的开发人员文档中找不到有用的链接,但这里有一个示例。
看起来覆盖和更高级的功能尚不可用,但这应该适用于很多用例。
编辑: w3c 有一个规范,iOS6 Safari 似乎实现了其中的一个子集。
capture
属性明显缺失。In iOS6, Apple supports this via the
<input type="file">
tag. I couldn't find a useful link in Apple's developer documentation, but there's an example here.It looks like overlays and more advanced functionality is not yet available, but this should work for a lot of use cases.
EDIT: The w3c has a spec that iOS6 Safari seems to implement a subset of. The
capture
attribute is notably missing.我认为这个正在发挥作用。
录制视频或音频;
或(新方法)
如果不是,可能会在 ios6 上工作,更多详细信息可以在 获取用户媒体
I think this one is working.
Recording a video or audio;
or (new method)
If it is not, probably will work on ios6, more detail can be found at get user media
更新 11/2020:Google Developer 链接(目前)已失效。仍然可以在 web.archive.org。
这个问题已经有几年的历史了,但那时已经发展了一些额外的可能性,例如直接访问相机、显示预览和捕获快照(例如用于二维码扫描)。
这篇 Google 开发者文章深入解释了所有 ( ?)如何将图像/相机数据导入 Web 应用程序,从“随处工作”(甚至在桌面浏览器中)到“仅在带有相机的现代最新移动设备上工作”。以及许多有用的提示。
方法说明:
请求 URL:最简单但最不令人满意。
文件输入(这里的大多数其他帖子都介绍过):然后可以通过侦听输入元素上的 onchange 事件,然后读取事件目标的 files 属性,将数据附加到 a 或使用 JavaScript 进行操作。
files
属性是一个 FileList 对象。您可以从
drop
事件的dataTransfer.files
属性获取一个FileList
对象。e.clipboardData.files
又是一个FileList
对象。constsupported = 'mediaDevices' in navigator;
检测相机支持并提示用户同意。然后显示实时预览并将快照复制到画布。不要忘记通过更新 11/2020 停止视频流
:Google Developer 链接(目前)已失效。仍然可以在 web.archive.org。
Update 11/2020: The Google Developer link is (currently) dead. The original article with a LOT more explanations can still be found at web.archive.org.
This question is already a few years old but in that time some additional possibilities have evolved, like accessing the camera directly, displaying a preview and capturing snapshots (e.g. for QR code scanning).
This Google Developers article provides an in-depth explaination of all (?) the ways how to get image/camera data into a web application, from "work everywhere" (even in desktop browsers) to "work only on modern, up-to-date mobile devices with camera". Along with many useful tips.
Explained methods:
Ask for a URL: Easiest but least satisfying.
File input (covered by most other posts here): The data can then be attached to a or manipulated with JavaScript by listening for an onchange event on the input element and then reading the files property of the event target.
The
files
property is a FileList object.You can get a
FileList
object from thedataTransfer.files
property of thedrop
event.e.clipboardData.files
is aFileList
object again.const supported = 'mediaDevices' in navigator;
and prompt the user for consent. Then show a realtime preview and copy snapshots to a canvas.Don't forget to stop the video stream with
Update 11/2020: The Google Developer link is (currently) dead. The original article with a LOT more explanations can still be found at web.archive.org.
Picup 应用程序是一种从 HTML5 页面拍摄照片并将其上传到服务器的方法。它需要在服务器上进行一些额外的编程,但除了PhoneGap之外,我还没有找到其他方法。
The Picup app is a way to take pictures from an HTML5 page and upload them to your server. It requires some extra programming on the server, but apart from PhoneGap, I have not found another way.