抖音开放平台Logo
控制台

Camera.setBeautifyParam
收藏
我的收藏

设置美颜参数,这是个同步 API。

语法

Camera.setBeautifyParam(whiten, smoothen, enlargeEye, slimFace)

参数说明

字段类型说明
whitennumber美白程度,范围[0-1]
smoothennumber磨皮程度, 范围[0-1]
enlargeEyenumber大眼强度,范围[0-1]
slimFacenumber瘦脸程度, 范围[0-1]

代码示例

console.log("开发字节跳动小游戏过程中可以参考以下文档:");
console.log("https://developer.toutiao.com/docs/game/");

const canvas = tt.createCanvas();
const ctx = canvas.getContext("2d");
const camera = tt.createCamera();
console.log("camera", camera);
camera.setBeautifyParam(0.8, 0.79, 0.4, 0.58);
camera
  .start("front", true, { matting: true })
  .then((video) => {
    draw(video);
  })
  .catch((err) => {
    tt.showToast({
      title: "相机需要授权",
    });
    console.log(err);
  });
// 3s 后暂停摄像头视频画面
setTimeout(() => {
  camera.pause();
}, 3000);

function draw(video) {
  let scale = video.videoHeight / video.videoWidth;
  video &&
    ctx.drawImage(
      video,
      0,
      0,
      video.videoWidth,
      video.videoHeight,
      0,
      0,
      canvas.width,
      canvas.width * scale,
    );
  requestAnimationFrame(function () {
    draw(video);
  });
}

Bug & Tip

  • Tip:开发者工具暂不支持此能力,请用真机扫码调试。
  • Tip:只有 Camera.start 开启摄像头美白, 调用该接口才能设置美白参数。

文档评论

登录后可参与评论