2***@qq.com
2***@qq.com
  • 发布:2018-10-24 10:40
  • 更新:2018-10-24 10:40
  • 阅读:2400

拍照后获取图片的宽,高,大小等信息

分类:HTML5+
plus.camera.getCamera().captureImage(function(absPath) {  
        //创建一个 bitmap 对象,参数1是id,参数2是拍照返回的图片绝对路径  
    var bitmap = new plus.nativeObj.Bitmap('test', absPath);  
        //没办法,费点事,再用 bitmap 保存一下,overwrite 属性表示是否覆盖原来文件,第1个回调是保存成功,第2个回调是保存失败  
    bitmap.save(  
        absPath,   
                {  
            overwrite: true,  
            format: 'jpg',  

        },  
        function(event) {  
            // Code here  
            // 保存后的图片url路径,以"file://"开头  
            var target = event.target;  
            // 保存后图片的大小,单位为字节(Byte)  
            var size = event.size;  
            // 保存后图片的实际宽度,单位为px  
            var width = event.width;  
            // 保存后图片的实际高度,单位为px    
            var height = event.height;  
            console.log('图片绝对路径: ' + target)  
            console.log('图片文件大小:' + size)  
            console.log('图片宽度:' + width)  
            console.log('图片高度:' + height)  

            function bytesToSize(bytes) {  
                if (bytes === 0) {  
                    return '0 B'  
                }  
                var k = 1000, // or 1024  
                sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],  
                i = Math.floor(Math.log(bytes) / Math.log(k));  

                return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];  
            }  
            var ss = bytesToSize(size);  
            console.log(ss)  
        },  
        function(error) {  
                                            // Error.  
            var code = error.code; // 错误编码  
            var message = error.message; // 错误描述信息                
            console.log(code)  
            console.log(message)  
        }  
    );  
}

其实我觉得 new plus.nativeObj.Bitmap('test', absPath) 后就应该包含了该有的信息了....

1 关注 分享
馨u

要回复文章请先登录注册