拍照

调用系统相机进行拍照

[!TIP|labelVisibility:hidden|iconVisibility:hidden] navigator.camera.takePhoto(captureSuccess,captureError,saveToAlbum,maxSize)

支持平台:

  • Android
  • iOS

参数说明

参数 类型 必填 说明
captureSuccess Function 拍照结果回调函数
captureError Function 拍照错误回调函数
saveToAlbum Boolean 图片是否保存在相册,true保存到相册,false保存到沙盒,默认保存到沙盒
maxSize Int 照片大小,单位kb,默认:200kb

captureSuccess返回拍照结果的一个对象,其属性包含以下一项或多项:

  • fullPath(String) -- 照片的全路径(含file:///)
  • lastModifiedDate(Number) -- 照片最后被修改的时间,单位毫秒
  • localURL(String) -- 照片本地URL(遵守cdvfile协议)
  • name(String) -- 照片名称
  • size(Number) -- 照片大小,单位 bytes
  • thumbLocalURL(String) -- 缩略图本地URL(遵守cdvfile协议)
  • type(String) -- 文件mine type类型

captureError返回一个对象,其属性包含以下一项或多项:

  • code(Int) -- 错误码,表示错误结果

示例代码

// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
// 监听’deviceready‘事件
document.addEventListener('deviceready', onDeviceReady, false)
function onDeviceReady(){
navigator.camera.takePhoto(function(success) {
        alert(JSON.stringify(success));
        },
        function(error) {
        alert(JSON.stringify(error));
        },true,1024);
}
</script>

响应示例代码:

{
    "fullPath": "file:///private/var/mobile/Containers/Data/Application/6D266368-6960-4C75-8DCB-EC3D2F37A9AF/tmp/IMG_0443.jpeg",
    "thumbLocalURL": "cdvfile://localhost/root/private/var/mobile/Containers/Data/Application/6D266368-6960-4C75-8DCB-EC3D2F37A9AF/tmp/IMG_0443_thumb.jpeg",
    "lastModifiedDate": 1584342725384.5444,
    "size": 1024276,
    "localURL": "cdvfile://localhost/temporary/IMG_0443.jpeg",
    "type": "image/jpeg",
    "name": "IMG_0443.jpeg"
}

results matching ""

    No results matching ""