【发布时间】:2011-11-15 07:44:56
【问题描述】:
我有一个关于从浏览器访问相机的问题。 (Android 和 iOS 浏览器)
谷歌和苹果在一年前宣布,从浏览器到相机的访问应该很快就会可用。
我需要此功能用于移动 Web 应用程序。
此功能现在可用吗?
【问题讨论】:
-
更新(2012 年 10 月)此功能现已在 ios6 和 android 3+ 中可用
标签: android ios web-applications
我有一个关于从浏览器访问相机的问题。 (Android 和 iOS 浏览器)
谷歌和苹果在一年前宣布,从浏览器到相机的访问应该很快就会可用。
我需要此功能用于移动 Web 应用程序。
此功能现在可用吗?
【问题讨论】:
标签: android ios web-applications
正如他们所说的,我确实使用了输入,并且在 iO 上工作得非常好。我可以从相机或相册中获取图片并设置一个 img 元素。
这里是代码:http://jsfiddle.net/2wZgv/
js:
<script>
oFReader = new FileReader();
oFReader.onload = function (oFREvent) {
document.getElementById("fotoImg").src = oFREvent.target.result;
document.getElementById("fotoImg").style.visibility = "visible";
var screenHeight = screen.availHeight;
screenHeight = screenHeight - 220;
document.getElementById("fotoImg").style.height = screenHeight;
};
$(function() {
$("input:file").change(function (){
var input = document.querySelector('input[type=file]');
var oFile = input.files[0];
oFReader.readAsDataURL(oFile);
});
});
</script>
【讨论】:
试试这个东西。
<video id="Video" autoplay="autoplay" audio="muted" width="100%" height ="100%"> </video>
<script type="text/javascript">
if (navigator.getUserMedia) {
var video = document.getElementById('Video');
video.src = null;
navigator.getUserMedia('video', successCallback, errorCallback);
//if everything if good then set the source of the video element to the mediastream
function successCallback(stream) {
video.src = stream;
}
//If everything isn't ok then say so
function errorCallback(error) {
alert("An error occurred: [CODE " + error.code + "]");
}
}
else {
//show no support for getUserMedia
alert("Native camera is not supported in this browser!");
}
</script>
但请记住,这仅适用于 Android 版 Opera Mobile。目前没有其他浏览器支持相机访问。据我所知,iOS 现在不支持此功能,将来可能会支持。
谢谢。
【讨论】:
尝试以下方法:
<html>
<body>
<form>
<input type="file" accept="image/*;capture=camera"/>
<input type="submit"/>
</form>
</body>
</html>
【讨论】:
【讨论】:
这是可能的。您可以通过浏览器应用程序访问相机。如果您正在通过 Phone Gap 进行开发,请查找 http://docs.phonegap.com/phonegap_camera_camera.md.html
这是PhoneGap中用于访问相机的相机API。
【讨论】: