• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

使用html5+,用plus.io进行拍照,图片等获取

武飞扬头像
多秋浮沉度华年
帮助1

html5 官网地址

使用Hbuilder开发工具开发:实现可对Android机进行控制和获取资源
说明:IO模块管理本地文件系统,用于对文件系统的目录浏览、文件的读取、文件的写入等操作。通过plus.io可获取文件系统管理对象

获取目录:常量:

  • 应用私有资源目录,对应常量plus.io.PRIVATE_WWW,仅应用自身可读
  • 应用私有文档目录,对应常量plus.io.PRIVATE_DOC,仅应用自身可读写
  • 应用公共文档目录,对应常量plus.io.PUBLIC_DOCUMENTS,多应用时都可读写,常用于保存应用间共享文件
  • 应用公共下载目录,对应常量plus.io.PUBLIC_DOWNLOADS,多应用时都可读写,常用于保存下载文件

以下有四个demo

<button @click.stop="videoCapture" class="delBtn">录像</button>
 <button @click.stop="captureImage" class="delBtn">拍照</button>
 <button @click.stop="getImage" class="delBtn">获取图片</button>
 <button @click.stop="getImageUrl" class="delBtn">获取图片目录</button>
//打开摄像头进行录像
videoCapture(){
					this.cmr = plus.camera.getCamera();
					var res = this.cmr.supportedVideoResolutions[0];
					var fmt = this.cmr.supportedVideoFormats[0];
					console.log("Resolution: " res ", Format: " fmt);
					this.cmr.startVideoCapture( function( path ){
							alert( "Capture video success: "   path );  
						},
						function( error ) {
							alert( "Capture video failed: "   error.message );
						},
						{resolution:res,format:fmt}
					);
					// 拍摄10s后自动完成 
					setTimeout( this.stopCapture, 10000 );
			},
学新通
//停止摄像头录像
			stopCapture(){
				console.log("stopCapture");
				this.cmr.stopVideoCapture()   //设备现在不支持,需要手动调用关闭摄像头
			},
//打开摄像头进行拍照
			captureImage(){
				var cmr = plus.camera.getCamera();
					var res = cmr.supportedImageResolutions[0];
					var fmt = cmr.supportedImageFormats[0];
					console.log("Resolution: " res ", Format: " fmt);
					cmr.captureImage( function( path ){
						//path   拍照成功获取到路径
							console.log(path)
						},
						function( error ) {   //取消拍照的函数
							console.log(error)
						},
						{resolution:res,format:fmt}
					)
			},
学新通
//根据路径获取图片参数
			getImage(){
				
				 plus.io.getImageInfo({
					 src: "/storage/emulated/0/Android/data/io.dcloud.HBuilder/apps/HBuilder/doc/1652421993337.jpg",
					 success: function(data){  
						console.log(JSON.stringify(data));  
					},  
					fail: function(err){  
						console.log(JSON.stringify(err));  
					}
				 })
			},
//获取根目录找到图片
			getImageUrl(){
				console.log(this)
				let that = this
				console.log(that)
				 // 应用私有文档目录常量
				plus.io.requestFileSystem( plus.io.PRIVATE_DOC , function(fs){
						// fs.root是根目录操作对象DirectoryEntry
						// 创建读取目录信息对象 
						var directoryReader = fs.root.createReader();
						console.log(directoryReader)
						directoryReader.readEntries( function( entries ){
							console.log( entries.length)
							var reg = /.(png|jpg|gif|jpeg|webp)$/;
							entries.forEach( item =>{
								console.log(item.name)
								if(reg.test(item.name)) {
									console.log(item.name)
									console.log(that.imageList)
									let name = '/storage/emulated/0/Android/data/io.dcloud.HBuilder/apps/HBuilder/doc/' item.name
									that.imageList.push(name)
									console.log(that.imageList)
								}
							})
							console.log(that.imageList)
						}, function ( e ) {
							alert( "Read entries failed: "   e.message );
						} );
					} );
			}
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgffcij
系列文章
更多 icon
同类精品
更多 icon
继续加载