网站的js效果代码大全课程资源网站的建设

张小明 2026/1/10 18:55:51
网站的js效果代码大全,课程资源网站的建设,鲁文建筑服务网,ui设计师培训费用【前言】在开发过程中#xff0c;经常有扫一扫功能#xff0c;可以通过相机直接扫码#xff0c;或者打开相册#xff0c;识别相册中的二维码#xff0c;下面介绍下如何实现一个扫码功能一、首先看下实现效果如下从布局上#xff0c;最上边是一个标题#xff0c;中间是不…【前言】在开发过程中经常有扫一扫功能可以通过相机直接扫码或者打开相册识别相册中的二维码下面介绍下如何实现一个扫码功能一、首先看下实现效果如下从布局上最上边是一个标题中间是不断上下扫描的动画最下边是两个按钮一个是打开闪光灯一个是打开相册这个布局可以自定义二、扫码的关键组件1、XComponent组件用来实时预览相机拍摄的图片2、ScanKit中的customScan系统工具类用来打开相机并实时识别相机中的二维码并将图片内容展示在XComponent组件中一旦捕获到二维码就会解析并将结果返回给我们3、ScanKit中的detectBarcode系统工具类可以识别解析相册返回的图片流并返回二维码信息三、代码实现代码实现步骤如下1、首先是布局总共两部分一个是XComponet用来实时展示相机拍摄的图片另一部分就是自定义标题扫描动画底部操作按钮2、要申请相机权限否则ScanKit没法正常打开相机权限申请可以参考我之前的文章3、customScan初始化并开启扫描由于customScan需要将相机的图片实时展示在XComponent组件中因此customScan初始化依赖XComponent组件的宽和高。特别是一些折叠屏需要开发者实时计算宽和高并重新初始化页面代码实现import { customScan, scanBarcode, scanCore } from kit.ScanKit; import hilog from ohos.hilog; import { display } from kit.ArkUI; import { PermissionUtils } from ../util/PermissionUtils; import { AlbumUtil } from ./AlbumUtil; const TAG: string [customScanPage]; Entry Component struct CustomScanPage { State translateY: number 0; State surfaceId: string // XComponent组件生成id State cameraHeight: number 640 // 设置预览流高度默认单位vp State cameraWidth: number 360 // 设置预览流宽度默认单位vp State userGrant: boolean false // 打开闪光灯 State flashlightState: boolean false private mXComponentController: XComponentController new XComponentController() async onPageShow() { // 自定义启动第一步用户申请权限 PermissionUtils.requestPermission(ohos.permission.CAMERA).then(grant { this.userGrant grant ?? false }) // 自定义启动第二步设置预览流布局尺寸 this.setDisplay(); } async onPageHide() { // 页面消失或隐藏时停止并释放相机流 this.releaseCamera(); } // 释放相机流 private async releaseCamera() { try { await customScan.stop(); await customScan.release(); } catch (error) { hilog.error(0x0001, TAG, Failed to release customScan. Code: ${error.code}, message: ${error.message}); } } // 竖屏时获取屏幕尺寸设置预览流全屏示例 setDisplay() { try { // 默认竖屏 let displayClass display.getDefaultDisplaySync(); let displayHeight this.getUIContext().px2vp(displayClass.height); let displayWidth this.getUIContext().px2vp(displayClass.width); let maxLen: number Math.max(displayWidth, displayHeight); let minLen: number Math.min(displayWidth, displayHeight); const RATIO: number 16 / 9; this.cameraHeight maxLen; this.cameraWidth maxLen / RATIO; } catch (error) { hilog.error(0x0001, TAG, Failed to getDefaultDisplaySync. Code: ${error.code}, message: ${error.message}); } } // toast显示扫码结果 async showScanResult(result: scanBarcode.ScanResult) { this.initAndStartCamera(); // 使用toast显示出扫码结果 this.getUIContext().getPromptAction().showToast({ message: 解析到的url为${result.originalValue}, duration: 5000 }); } async initAndStartCamera() { this.releaseCamera() let viewControl: customScan.ViewControl { // xComponent的宽和高 width: this.cameraWidth, height: this.cameraHeight, surfaceId: this.surfaceId }; // 多码扫码识别enableMultiMode: true 单码扫码识别enableMultiMode: false let options: scanBarcode.ScanOptions { scanTypes: [scanCore.ScanType.ALL], enableMultiMode: true, enableAlbum: true } try { // 自定义启动第三步初始化接口 customScan.init(options); // 自定义启动第四步请求扫码接口通过Promise方式回调 let result: scanBarcode.ScanResult[] await customScan.start(viewControl) this.showScanResult(result[0]) } catch (error) { hilog.error(0x0001, TAG, Failed to start customScan. Code: ${error.code}, message: ${error.message}); } } build() { Stack() { if (this.userGrant) { Column() { XComponent({ id: componentId, type: XComponentType.SURFACE, controller: this.mXComponentController }) .onLoad(async () { // 获取XComponent组件的surfaceId this.surfaceId this.mXComponentController.getXComponentSurfaceId(); this.initAndStartCamera(); }) .width(this.cameraWidth) .height(this.cameraHeight) } .height(100%) .width(100%) } Column() { this.TopTips() this.buildScanAnimator() this.buildBottom() } } .width(100%) .height(100%) } // 自定义扫码界面的顶部返回按钮和扫码提示 Builder TopTips() { Column({ space: 8 }) { Text(扫描二维码) .fontColor(Color.White) Text(对准二维码即可自动扫描) .fontColor(Color.White) } .height(146) .width(100%) } // 扫描动画 Builder buildScanAnimator() { Column() { Row() .width(90%) .height(8) .backgroundColor(Color.Blue) .translate({ y: this.translateY }) .opacity(0.4) .animation({ duration: 2500, curve: Curve.EaseInOut, iterations: -1, playMode: PlayMode.Alternate }) }.onAppear(() { this.translateY 240 }).height(40%) .width(100%) } // 构建底部按钮打开关闭闪光灯、打开相册 Builder buildBottom() { Row() { Column({ space: 8 }) { if (this.flashlightState) { SymbolGlyph($r(sys.symbol.flashlight_on_fill)) .fontColor([Color.White]) .onClick(() { customScan.closeFlashLight() this.flashlightState !this.flashlightState }) Text(关闭) .fontSize(14) .fontColor(Color.White) } else { SymbolGlyph($r(sys.symbol.flashlight_off_fill)) .fontColor([Color.White]) .onClick(() { customScan.openFlashLight() this.flashlightState !this.flashlightState }) Text(打开) .fontSize(14) .fontColor(Color.White) } } Column({ space: 8 }) { SymbolGlyph($r(sys.symbol.rectangle_on_rectangle_fill)) .fontColor([Color.White]) .onClick(() { AlbumUtil.openAlbum().then(result { if (result.length 0) { this.showScanResult(result[0]) } }) }) Text(相册) .fontSize(14) .fontColor(Color.White) } }.justifyContent(FlexAlign.SpaceBetween) .padding({left:56,right:56}) .width(100%) } }打开相册并识别相册图片二维码的工具类import { detectBarcode, scanBarcode, scanCore } from kit.ScanKit; import { photoAccessHelper } from kit.MediaLibraryKit; export class AlbumUtil { static async openAlbum(): PromisescanBarcode.ScanResult[] { const photoSelectOptions: photoAccessHelper.PhotoSelectOptions { MIMEType: photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE, maxSelectNumber: 1, isPhotoTakingSupported: false, isEditSupported: false }; const photoPicker: photoAccessHelper.PhotoViewPicker new photoAccessHelper.PhotoViewPicker(); try { const photoSelectResult: photoAccessHelper.PhotoSelectResult await photoPicker.select(photoSelectOptions); if (photoSelectResult photoSelectResult.photoUris photoSelectResult.photoUris.length 0) { return AlbumUtil.decodeAlbum(photoSelectResult.photoUris[0]); } } catch (error) { } return [] } static async decodeAlbum(uri: string): PromisescanBarcode.ScanResult[] { const inputImage: detectBarcode.InputImage { uri }; try { const scanResults: ArrayscanBarcode.ScanResult await detectBarcode.decode(inputImage, { scanTypes: [scanCore.ScanType.ALL], enableMultiMode: false, enableAlbum: true }); if (scanResults scanResults.length 0) { return [scanResults[0]] } else { return [] } } catch (error) { return [] } } }
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

京粉购物网站怎么做市场营销课程

光谱共焦技术凭借非接触、高精度、抗干扰性强的优势,在微观尺寸测量领域占据重要地位。但单一的光谱共焦传感器仅能实现“点测量”,难以满足工业场景中对大面积、复杂形态物体(如透明玻璃/薄膜、复杂曲面零件)的检测需求。通过与高…

张小明 2026/1/4 1:09:35 网站建设

dedecms 门户网站网站站建设建设中页中页

目录10.1 函数模板的引入10.2 调用模板函数10.2.1 显式实例化10.2.2 隐式实例化10.3 模板函数应用实例10.4 C concept(C20)10.4.1 一个错误10.4.2 创建10.4.3 使用10.4.4 实例10.5 可变参数模板10.5.1 实现10.5.2 编译器运行可变参数模板10.5.3 可变模板…

张小明 2026/1/3 14:10:22 网站建设

曹县网站建设网站制作的困难和解决方案

还在为无法保存网页中的精彩视频而烦恼吗?想要将喜欢的在线课程、短视频内容永久保存到本地吗?今天我要向您介绍一款简单实用的视频下载工具,让您轻松掌握网页视频保存技巧。 【免费下载链接】VideoDownloadHelper Chrome Extension to Help …

张小明 2026/1/9 1:49:50 网站建设

asp网站制作免费模板下载做网站应该做哪方面的

大文件传输系统解决方案 项目需求分析 作为山西IT行业软件公司的项目负责人,我分析了公司产品部门提出的大文件传输功能需求,该需求具有以下关键点: 超大文件支持:单文件100G左右传输能力文件夹处理:保留层级结构的…

张小明 2026/1/3 13:56:46 网站建设

网站开发如何使用API网站404网页界面psd源文件模板

快速体验 打开 InsCode(快马)平台 https://www.inscode.net输入框内输入如下内容: 创建一个交互式学习位运算的AI助手,能够根据用户输入的数字或问题,实时展示位运算过程(如与、或、异或、位移等),并提供优…

张小明 2026/1/3 17:36:06 网站建设

网站美工怎么做中国工程建设工程造价管理协会网站

B站漫画下载器超详细使用教程:新手也能轻松掌握 【免费下载链接】BiliBili-Manga-Downloader 一个好用的哔哩哔哩漫画下载器,拥有图形界面,支持关键词搜索漫画和二维码登入,黑科技下载未解锁章节,多线程下载&#xff0…

张小明 2026/1/4 19:06:22 网站建设