html5直接调用手机相机照相/录像

现在的h5功能越来越强大。之前做项目时上传功能input type=file时,在IOS下居然可以直接照相。。。但是在安卓上是不能。后面研究 了下,其实安卓下也可以的。

就是在input上加上capture属性。至于capture是属性是什么。查到是下图这样解释。

html5直接调用手机相机照相/录像

然后举个例子。

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>html5直接调用手机相机照相/录像</title> </head> <body> </body> <div> <h3>使用设备的面向用户的相机拍摄照片</h3> <form> <input type="file" name="image" accept="image/*" capture="user"> <input type="submit" value="照相上传"> </form> </div> <div> <h3>使用面向环境的设备本地摄像机捕获视频:</h3> <form> <input type="file" name="video" accept="video/*" capture="environment"> <input type="submit" value="录像上传"> </form> </div> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zgddyd.html