• 设为首页
  • 收藏本站
  • 积分充值
  • VIP赞助
  • 手机版
  • 微博
  • 微信
    微信公众号 添加方式:
    1:搜索微信号(888888
    2:扫描左侧二维码
  • 快捷导航
    福建二哥 门户 查看主题

    html5+实现plus.io进行拍照和图片等获取

    发布者: 涵韵 | 发布时间: 2025-6-16 12:19| 查看数: 36| 评论数: 0|帖子模式

    html5+官网地址
    使用Hbuilder开发工具开发:实现可对Android机进行控制和获取资源
    说明:IO模块管理本地文件系统,用于对文件系统的目录浏览、文件的读取、文件的写入等操作。通过plus.io可获取文件系统管理对象
    获取目录:常量:
         
    • 应用私有资源目录,对应常量plus.io.PRIVATE_WWW,仅应用自身可读   
    • 应用私有文档目录,对应常量plus.io.PRIVATE_DOC,仅应用自身可读写   
    • 应用公共文档目录,对应常量plus.io.PUBLIC_DOCUMENTS,多应用时都可读写,常用于保存应用间共享文件   
    • 应用公共下载目录,对应常量plus.io.PUBLIC_DOWNLOADS,多应用时都可读写,常用于保存下载文件
    以下有四个demo
    1. <button @click.stop="videoCapture" class="delBtn">录像</button>
    2. <button @click.stop="captureImage" class="delBtn">拍照</button>
    3. <button @click.stop="getImage" class="delBtn">获取图片</button>
    4. <button @click.stop="getImageUrl" class="delBtn">获取图片目录</button>
    复制代码
    1. //打开摄像头进行录像
    2. videoCapture(){
    3.                     this.cmr = plus.camera.getCamera();
    4.                     var res = this.cmr.supportedVideoResolutions[0];
    5.                     var fmt = this.cmr.supportedVideoFormats[0];
    6.                     console.log("Resolution: "+res+", Format: "+fmt);
    7.                     this.cmr.startVideoCapture( function( path ){
    8.                             alert( "Capture video success: " + path );  
    9.                         },
    10.                         function( error ) {
    11.                             alert( "Capture video failed: " + error.message );
    12.                         },
    13.                         {resolution:res,format:fmt}
    14.                     );
    15.                     // 拍摄10s后自动完成
    16.                     setTimeout( this.stopCapture, 10000 );
    17.             },
    复制代码
    1. //停止摄像头录像
    2.             stopCapture(){
    3.                 console.log("stopCapture");
    4.                 this.cmr.stopVideoCapture()   //设备现在不支持,需要手动调用关闭摄像头
    5.             },
    复制代码
    1. //打开摄像头进行拍照
    2.             captureImage(){
    3.                 var cmr = plus.camera.getCamera();
    4.                     var res = cmr.supportedImageResolutions[0];
    5.                     var fmt = cmr.supportedImageFormats[0];
    6.                     console.log("Resolution: "+res+", Format: "+fmt);
    7.                     cmr.captureImage( function( path ){
    8.                         //path   拍照成功获取到路径
    9.                             console.log(path)
    10.                         },
    11.                         function( error ) {   //取消拍照的函数
    12.                             console.log(error)
    13.                         },
    14.                         {resolution:res,format:fmt}
    15.                     )
    16.             },
    复制代码
    1. //根据路径获取图片参数
    2.             getImage(){
    3.                
    4.                  plus.io.getImageInfo({
    5.                      src: "/storage/emulated/0/Android/data/io.dcloud.HBuilder/apps/HBuilder/doc/1652421993337.jpg",
    6.                      success: function(data){  
    7.                         console.log(JSON.stringify(data));  
    8.                     },  
    9.                     fail: function(err){  
    10.                         console.log(JSON.stringify(err));  
    11.                     }
    12.                  })
    13.             },
    复制代码
    1. //获取根目录找到图片
    2.             getImageUrl(){
    3.                 console.log(this)
    4.                 let that = this
    5.                 console.log(that)
    6.                  // 应用私有文档目录常量
    7.                 plus.io.requestFileSystem( plus.io.PRIVATE_DOC , function(fs){
    8.                         // fs.root是根目录操作对象DirectoryEntry
    9.                         // 创建读取目录信息对象
    10.                         var directoryReader = fs.root.createReader();
    11.                         console.log(directoryReader)
    12.                         directoryReader.readEntries( function( entries ){
    13.                             console.log( entries.length)
    14.                             var reg = /.(png|jpg|gif|jpeg|webp)$/;
    15.                             entries.forEach( item =>{
    16.                                 console.log(item.name)
    17.                                 if(reg.test(item.name)) {
    18.                                     console.log(item.name)
    19.                                     console.log(that.imageList)
    20.                                     let name = '/storage/emulated/0/Android/data/io.dcloud.HBuilder/apps/HBuilder/doc/'+item.name
    21.                                     that.imageList.push(name)
    22.                                     console.log(that.imageList)
    23.                                 }
    24.                             })
    25.                             console.log(that.imageList)
    26.                         }, function ( e ) {
    27.                             alert( "Read entries failed: " + e.message );
    28.                         } );
    29.                     } );
    30.             }
    复制代码
    到此这篇关于html5+实现plus.io进行拍照和图片等获取的文章就介绍到这了,更多相关html5+拍照和图片获取内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!

    来源:https://www.jb51.net/html5/830622.html
    免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

    最新评论

    QQ Archiver 手机版 小黑屋 福建二哥 ( 闽ICP备2022004717号|闽公网安备35052402000345号 )

    Powered by Discuz! X3.5 © 2001-2023

    快速回复 返回顶部 返回列表