Vue + Cordova 相册/相机

/* eslint-disable no-undef */

export const openAlbum = () => {
  return new Promise((resolve, reject) => {
    navigator.camera.getPicture(onSuccess, onFail, {
      quality: 50,
      destinationType: Camera.DestinationType.DATA_URL,
      sourceType: 0
    })

    function onSuccess (imageData) {
      resolve('data:image/jpeg;base64,' + imageData)
    }

    function onFail (message) {
      reject(message)
      alert(message)
    }
  })
}

export const takePicture = () => {
  return new Promise((resolve, reject) => {
    navigator.camera.getPicture(onSuccess, onFail, {
      quality: 50,
      destinationType: Camera.DestinationType.DATA_URL,
      sourceType: 1
    })

    function onSuccess (imageData) {
      resolve('data:image/jpeg;base64,' + imageData)
    }

    function onFail (message) {
      reject(message)
      alert(message)
    }
  })
}

猜你喜欢

转载自blog.csdn.net/CDUT100/article/details/80891243