我目前正在使用 Visual Studio 处理我的项目,我需要一个允许按下按钮打开相机的功能。我有一些以前项目的代码,但它们现在似乎不起作用。以下是我的代码。
js:
function getImage() {
// Retrieve image file location from specified source
navigator.camera.getPicture(uploadPhoto,
function (message) { alert('get picture failed'); },
{ quality: 10, destinationType: navigator.camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY }
);
}
HTML:
<form id="buyforme">
<img id="myimg" height="100">
<input type="button" name="selectimg" id="selectimg" onclick="getImage();" value="Take a picture of this item :)">
如果您还有其他需要知道的,请告知并告诉我!谢谢大家!
最佳答案
要在android
或ios
中访问手机相机以获取照片
或视频
,您可以简单地使用输入[type="file"]
像这样:
获取照片:
<input type="file" accept="image/*" capture="camera">
获取视频:
<input type="file" name="video" accept="video/*" capture="environment">
打开后置摄像头:
<input type="file" name="image" accept="image/*" capture="environment">
自拍相机(正面):
<input type="file" name="image" accept="image/*" capture="user">
关于javascript - 如何在 Android 应用程序上访问相机 onclick?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47325356/