plus.camera.getCamera 在uni-app中不能默认使用前置摄像头
plus.camera.getCamera 在uni-app中不能默认使用前置摄像头
开发环境 | 版本号 | 项目创建方式 |
---|---|---|
Windows | win10 64 | HBuilderX |
操作步骤:
也就是 几句代码 var cmr = plus.camera.getCamera(2); var res = cmr.supportedImageResolutions[0]; var fmt = cmr.supportedImageFormats[0]; console.log("Resolution: “+res+”, Format: "+fmt); cmr.captureImage( function( path ){ console.log(res);
### 预期结果:
想默认打开前置
实际结果:
一直打开的都是后置
更多关于plus.camera.getCamera 在uni-app中不能默认使用前置摄像头的实战教程也可以访问 https://www.itying.com/category-93-b0.html
这个 captureImage 的参数有一个 CameraOptions ,通过这个 参数可以控制摄像头 https://www.html5plus.org/doc/zh_cn/camera.html#plus.camera.CameraOptions
更多关于plus.camera.getCamera 在uni-app中不能默认使用前置摄像头的实战教程也可以访问 https://www.itying.com/category-93-b0.html
不行啊还是不能打开前置摄像头,只能打开后面的
//获取摄像头管理对象 var camera = plus.camera.getCamera(2); //分辨率 var res = camera.supportedImageResolutions[0]; //文件格式 var fmt = camera.supportedImageFormats[0]; //图片文件保存的路径 console.log(camera) camera.captureImage( (path) => { console.log("拍照成功,图片路径是: " + path); }, (error) => { console.log("拍照失败: " + error.message); }, { resolution: res, format: fmt, index:“2” } );
安卓好像只能切换
本来以为是个很简单的事情,没想到这么扯淡
在uni-app中使用plus.camera.getCamera(2)
确实应该调用前置摄像头,但实际打开后置摄像头的问题可能由以下原因导致:
-
设备兼容性问题:部分Android设备可能不支持前置摄像头调用,或需要特殊权限
-
代码修正建议:
// 确保参数正确
var cmr = plus.camera.getCamera(1); // 1表示前置摄像头
if(cmr){
// 获取支持的分辨率和格式
var res = cmr.supportedImageResolutions[0];
var fmt = cmr.supportedImageFormats[0];
cmr.captureImage(function(path){
console.log("Image saved: " + path);
});
} else {
console.log("前置摄像头不可用");
}