Camera
相机组件。一个页面仅支持一个camera组件。
子组件
不支持
属性
样式
事件
通用
方法
takePhoto |
CameraTakePhotoOptions |
执行拍照 |
---|---|---|
CameraTakePhotoOptions
quality |
string |
图片质量(L3) |
---|---|---|
success |
Function |
接口调用成功,返回uri |
fail |
Function |
接口调用失败 |
complete |
Function |
接口调用结束 |
CameraRecordOptions
success |
Function |
接口调用成功,返回uri |
---|---|---|
fail |
Function |
接口调用失败 |
complete |
Function |
接口调用结束 |
示例
<div style=" flex-direction: column; align-content: center;" >
<div style="height: {{heights}};width: {{widths}} ;">
<camera id="cameraId" style="height: 100%;width: 100%;"> </camera>
</div>
<text > src: {{src}} photoUri: {{photoUri}} </text>
<div style="height: 200; align-items: center;" >
<image style=" border-radius: 150; width: 200; height: 200; margin-left: 10; margin-right: 30;
object-fit: fill; background-color: black;" src="{{photoUri}}" ></image>
<button style=" border-radius: 150; height: 200; width: 200; margin-right: 30;"
onclick="takePhoto" value="takePhoto"></button>
</div>
<div style="flex-direction: row;height: 200;">
<button value="录像" onclick="startRecord" style="width: 50%;height: 200;"></button>
<button value="结束录像" onclick="closeRecord" style="width: 50%;height: 200;"></button>
</div>
</div>
//.js
import router from '@system.router';
export default {
data: {
photoUri: "",
val: "",
arr:[],
size: -1,
quality:'',
src:'',
heights: 600,
widths:600,
},
onInit() {
},
startRecord() {
this.$element('cameraId').startRecorder();
},
closeRecord() {
this.$element('cameraId').closeRecorder(
{
success: (res) => {
this.src = res.uri;
},
fail: (res) => {
this.val = "fail " + res.errormsg + " " + res.errorcode;
},
complete : (res) => {
this.val += " :complete";
},
}
);
},
takePhoto() {
this.$element('cameraId').takePhoto(
{
quality: -1,
success: (res) => {
this.photoUri = res.uri;
},
fail: (res) => {
this.val = "fail " + res.errormsg + " " + res.errorcode;
},
complete : (res) => {
this.val += " :complete";
},
}
);
},
}