网站建设属于哪个税目中国建筑集团领导名单

张小明 2026/3/2 23:12:34
网站建设属于哪个税目,中国建筑集团领导名单,烟台网站建设学校,湘潭网站建设方案案例Flutter在鸿蒙平台实现相机预览的技术实践 大家好#xff0c;今天我们一起来看一下使用相机调用这个案例#xff0c;一起来看一下flutter代码运行到鸿蒙平台的效果 首先大家需要下载这个仓库 testcamera 1.下载代码 git clone gitgitcode.com:openharmony-tpc/flutter_s…Flutter在鸿蒙平台实现相机预览的技术实践大家好今天我们一起来看一下使用相机调用这个案例一起来看一下flutter代码运行到鸿蒙平台的效果首先大家需要下载这个仓库testcamera1.下载代码git clone gitgitcode.com:openharmony-tpc/flutter_samples.git2.适配ohos的案例都在ohos目录下AUTHORSadd_to_appdeeplink_store_examplegoogle_mapsplace_trackersimplistic_editor COMMITTERS.mdanalysis_defaultsdesktop_photo_searchinfinite_listplatform_channelstesting_app CONTRIBUTING.mdandroid_splash_screendocsios_app_clipplatform_component_demotool LICENSEanimationsexperimentalisolate_exampleplatform_designveggieseasons OAT.xmlasset_transformationflutter_maps_firestorejsonexampleplatform_view_swiftweb PATENTSbackground_isolate_channelsflutter_music_playermaterial_3_demoprovider_counterweb_embedding README.OpenSourcecode_sharingflutter_smart_agriculturenavigation_and_routingprovider_shopper README.en.mdcompass_appform_appnext_gen_ui_demosimple_shader README.mdcontext_menusgame_templateohossimplistic_calculator ​cd到ohos目录下现在这里面就是我们的这些适配了ohos的目录README.mdevent_bus_testhttp_testpath_parsing_testsqflite_test animation_demofloor_testjs_dart_demoperformancestring_scanner_test async_testflutter-pagload_native_resource_demopetitparser_testtest_uni_links asynchronousflutter_huawei_loginlocaltion_demopictures_provider_demotestcamera automated_testing_demoflutter_ohos_theme_fontsizescalelogging_testplatform_demotestchat cached_network_image_sampleflutter_page_sample1multi_productsplatform_testtestpicture channel_demoflutter_page_sample2node_test_serverplatformchannel_demotuple_test clock_testflutter_svg_testohos_flutter_photoviewpickerprovider_partrefreshuuid_test component_demoflutter_webview_demoohos_sqlite3_demorxdart_testvector_math_test dio_testgesture_intercept_demoohos_themeAdaptationscrollview_demovideo_full_screen docshttp_parser_testpath_drawing_testsqflite_helperxml_test我今天想学习的是testcamera3.进入testcamera目录cd testcamera4.现在就可以直接使用flutter run来测试了。这个时候会报错 flutter_lints 2.0.3 (6.0.0 available) flutter_test 0.0.0 from sdk flutter leak_tracker 10.0.9 (11.0.2 available) leak_tracker_flutter_testing 3.0.9 (3.0.10 available) leak_tracker_testing 3.0.1 (3.0.2 available) lints 2.1.1 (6.0.0 available) matcher 0.12.17 (0.12.18 available) material_color_utilities 0.11.1 (0.13.0 available) meta 1.16.0 (1.17.0 available) path 1.9.1 sky_engine 0.0.0 from sdk flutter source_span 1.10.1 stack_trace 1.12.1 stream_channel 2.1.4 string_scanner 1.4.1 term_glyph 1.2.2 test_api 0.7.4 (0.7.8 available) vector_math 2.1.4 (2.2.0 available) vm_service 15.0.0 (15.0.2 available) Changed 27 dependencies! 12 packages have newer versions incompatible with dependency constraints. Try flutter pub outdated for more information. Launching lib/main.dart on 2LQ0224129000383 in debug mode... start hap build... Running Hvigor task assembleHap... 15.1s Error: 请通过DevEco Studio打开ohos工程后配置调试签名(File - Project Structure - Signing Configs 勾选Automatically generate signature) ​ ​所以需要大家在这里面ohos模块签名找到对应的文件5.打开deveco。签名6.现在就可以尝试了flutter run Launching lib/main.dart on 2LQ0224129000383 in debug mode... start hap build... Running Hvigor task assembleHap... 10.7s ✓ Built ohos/entry/build/default/outputs/default/entry-default-signed.hap. installing hap. bundleName: com.example.testcamera 12-18 08:07:00.014 24792 24792 W A00000/com.example.testcamera/XComFlutterOHOS_Native: flutter settings log message: build textureId :-1 12-18 08:07:00.281 24792 24792 W A00000/com.example.testcamera/XComFlutterOHOS_Native: flutter settings log message: build textureId :1 waiting for a debug connection: http://127.0.0.1:55220/qL6lfbc1GRE/ Syncing files to device 2LQ0224129000383... 72ms ​ Flutter run key commands. r Hot reload. ​已经运行成功。现在我们就可以对现在的源码继续分享了。一、项目概述本项目展示了如何在鸿蒙OpenHarmony平台上使用Flutter框架实现相机预览功能。这是一个典型的跨平台开发场景通过Flutter的插件机制将鸿蒙原生的相机能力桥接到Flutter应用中实现了高性能的相机预览体验。技术栈Flutter框架用于UI层和业务逻辑ArkTS鸿蒙原生开发语言用于实现相机插件MethodChannelFlutter与原生平台通信的桥梁TextureFlutter的纹理渲染机制用于显示相机预览流二、技术架构2.1 整体架构┌─────────────────────────────────────────┐ │ Flutter UI Layer │ │ (CameraPage.dart - Material Design) │ └──────────────┬──────────────────────────┘ │ MethodChannel │ (CameraControlChannel) ┌──────────────▼──────────────────────────┐ │ Flutter Plugin Bridge │ │ (CameraPlugin.ets - FlutterPlugin) │ └──────────────┬──────────────────────────┘ │ TextureRegistry │ (Surface ID) ┌──────────────▼──────────────────────────┐ │ HarmonyOS Camera API │ │ (ohos.multimedia.camera) │ └─────────────────────────────────────────┘2.2 数据流向Flutter端通过MethodChannel发送指令注册纹理、启动相机插件层接收指令调用鸿蒙相机API创建纹理Surface相机层将预览流输出到Surface渲染层通过Texture将Surface内容渲染到Flutter Widget三、Flutter端实现3.1 主入口main.dartimport package:flutter/material.dart; ​ import CameraPage.dart; ​ void main() { runApp(const MyApp()); } ​ class MyApp extends StatelessWidget { const MyApp({super.key}); ​ // This widget is the root of your application. override Widget build(BuildContext context) { return MaterialApp( title: Flutter Demo, theme: ThemeData( // This is the theme of your application. // // Try running your application with flutter run. Youll see the // application has a blue toolbar. Then, without quitting the app, try // changing the primarySwatch below to Colors.green and then invoke // hot reload (press r in the console where you ran flutter run, // or simply save your changes to hot reload in a Flutter IDE). // Notice that the counter didnt reset back to zero; the application // is not restarted. primarySwatch: Colors.blue, ), home: const CameraPage(), ); } }主入口非常简洁直接启动CameraPage作为首页。3.2 相机页面CameraPage.dart这是Flutter端的核心实现展示了如何使用MethodChannel和Textureimport package:flutter/material.dart; import package:flutter/services.dart; import dart:math as math; ​ class CameraPage extends StatefulWidget { const CameraPage({super.key}); override _CameraPageState createState() _CameraPageState(); } ​ class _CameraPageState extends StateCameraPage { final MethodChannel _channel MethodChannel(CameraControlChannel); ​ int textureId -1; ​ override void initState() { super.initState(); ​ newTexture(); startCamera(); } ​ override void dispose() { super.dispose(); if (textureId 0) { _channel.invokeMethod(unregisterTexture, {textureId: textureId}); } } ​ void startCamera() async { await _channel.invokeMethod(startCamera); } ​ void newTexture() async { int id await _channel.invokeMethod(registerTexture); setState(() { this.textureId id; }); } ​ Widget getTextureBody(BuildContext context) { return Container( width: 500, height: 500, child: Texture( textureId: textureId, ), ); } ​ override Widget build(BuildContext context) { Widget body textureId 0 ? getTextureBody(context) : Text(loading...); print(build textureId :$textureId); ​ return Scaffold( appBar: AppBar( title: Text(daex_texture), ), body: Container( color: Colors.white, height: 500, child: Center( child: body, ), ), ); } }关键技术点MethodChannel通信通道名称CameraControlChannel必须与原生端保持一致三个核心方法registerTexture注册纹理获取textureIdstartCamera启动相机预览unregisterTexture释放纹理资源Texture WidgetFlutter提供的原生纹理渲染组件通过textureId与原生平台的Surface绑定实现零拷贝的高性能渲染生命周期管理initState初始化时注册纹理并启动相机dispose页面销毁时释放纹理资源防止内存泄漏四、鸿蒙端实现ArkTS4.1 插件注册EntryAbility.etsimport { FlutterAbility } from ohos/flutter_ohos import { GeneratedPluginRegistrant } from ../plugins/GeneratedPluginRegistrant; import FlutterEngine from ohos/flutter_ohos/src/main/ets/embedding/engine/FlutterEngine; import { CameraPlugin } from ../cameraplugin/CameraPlugin; ​ export default class EntryAbility extends FlutterAbility { configureFlutterEngine(flutterEngine: FlutterEngine) { super.configureFlutterEngine(flutterEngine) GeneratedPluginRegistrant.registerWith(flutterEngine) this.addPlugin(new CameraPlugin()); } }插件在Flutter引擎初始化时注册确保在应用启动时即可使用。4.2 相机插件CameraPlugin.ets这是整个插件的核心实现了FlutterPlugin和MethodCallHandler接口export class CameraPlugin implements FlutterPlugin, MethodCallHandler { private binding: FlutterPluginBinding | null null; private mMethodChannel: MethodChannel | null null; private textureRegistry: TextureRegistry | null null; private textureId: number -1; private surfaceId: number -1; ​ getUniqueClassName(): string { return TAG; } ​ onAttachedToEngine(binding: FlutterPluginBinding): void { Log.e(TAG, CameraPlugin onAttachedToEngine); this.binding binding; this.mMethodChannel new MethodChannel(binding.getBinaryMessenger(), CameraControlChannel); this.mMethodChannel.setMethodCallHandler(this); this.textureRegistry binding.getTextureRegistry(); ​ } ​ onDetachedFromEngine(binding: FlutterPluginBinding): void { this.binding null; this.mMethodChannel null; } ​ onMethodCall(call: MethodCall, result: MethodResult): void { let method: string call.method; Log.e(TAG, Received method message.); switch (method) { case registerTexture: this.registerCameraTexture(); result.success(this.textureId); break; case startCamera: this.startCamera(); result.success(null); break; case unregisterTexture: this.unregisterTexture(call.argument(textureId)); result.success(null); break; } } ​ getTextureId(): number { return this.textureId } ​ registerCameraTexture(): void { Log.i(TAG, start register Camera texture in flutter engine); this.textureId this.textureRegistry!.getTextureId(); this.surfaceId this.textureRegistry!.registerTexture(this.textureId)!.getSurfaceId(); } ​ unregisterTexture(textureId: number): void { this.textureRegistry!.unregisterTexture(textureId); } ​ startCamera() { checkPermissions(permissions).then((value: boolean) { if (value) { this.startSession(); } else { // 获取权限 reqPermissionsFromUser(permissions, getContext(this) as Context).then((value: boolean) { if (value) { this.startSession(); } else { console.log([camera test] 授权失败); } }); } }); } ​ startSession() { console.log([camera test] 已经授权相机开始拍摄); let cameraManager getCameraManager(getContext(this) as common.BaseContext); let cameraDevices getCameraDevices(cameraManager); let cameraInput getCameraInput(cameraDevices[0], cameraManager); if (cameraInput ! null) { getSupportedOutputCapability(cameraDevices[0], cameraManager, cameraInput) .then((supportedOutputCapability) { if (supportedOutputCapability ! undefined) { let previewOutput getPreviewOutput(cameraManager, supportedOutputCapability, this.surfaceId.toString()); let captureSession getCaptureSession(cameraManager); if (captureSession ! undefined previewOutput ! undefined cameraInput ! null) { beginConfig(captureSession); setSessionCameraInput(captureSession, cameraInput); setSessionPreviewOutput(captureSession, previewOutput); startSession(captureSession); } } }); } } }核心流程插件生命周期onAttachedToEngine创建MethodChannel获取TextureRegistryonDetachedFromEngine清理资源纹理注册从TextureRegistry获取唯一的textureId注册纹理并获取对应的Surface IDSurface ID将用于相机预览输出相机启动流程权限检查 → 获取相机管理器 → 创建输入流 → 获取输出能力 → 创建预览输出 → 配置会话 → 启动会话4.3 相机工具类CameraUtil.ets封装了鸿蒙相机API的调用逻辑export function getCameraManager(context: common.BaseContext): camera.CameraManager { let cameraManager: camera.CameraManager camera.getCameraManager(context); return cameraManager; } ​ /** * 通过cameraManager类中的getSupportedCameras()方法获取当前设备支持的相机列表列表中存储了设备支持的所有相机ID。 * 若列表不为空则说明列表中的每个ID都支持独立创建相机对象否则说明当前设备无可用相机不可继续后续操作。 * param cameraManager * returns */ export function getCameraDevices(cameraManager: camera.CameraManager): Arraycamera.CameraDevice { let cameraArray: Arraycamera.CameraDevice cameraManager.getSupportedCameras(); if (cameraArray ! undefined cameraArray.length 0) { console.error([camera test] cameraManager.getSupportedCameras error); return []; } for (let index 0; index cameraArray.length; index) { console.info([camera test] cameraId : cameraArray[index].cameraId); // 获取相机ID console.info([camera test] cameraPosition : cameraArray[index].cameraPosition); // 获取相机位置 console.info([camera test] cameraType : cameraArray[index].cameraType); // 获取相机类型 console.info([camera test] connectionType : cameraArray[index].connectionType); // 获取相机连接类型 } return cameraArray; } ​ /** * 调用cameraManager类中的createCaptureSession()方法创建一个会话 * param cameraManager * returns */ export function getCaptureSession(cameraManager: camera.CameraManager): camera.CaptureSession | undefined { let captureSession: camera.CaptureSession | undefined undefined; try { captureSession cameraManager.createCaptureSession(); } catch (error) { let err error as BusinessError; console.error([camera test] Failed to create the CaptureSession instance. error: ${JSON.stringify(err)}); } return captureSession; } ​ /** * 调用captureSession类中的beginConfig()方法配置会话 * param captureSession */ export function beginConfig(captureSession: camera.CaptureSession): void { try { captureSession.beginConfig(); } catch (error) { let err error as BusinessError; console.error([camera test] Failed to beginConfig. error: ${JSON.stringify(err)}); } } ​ /** * 调用captureSession类中的commitConfig()和start()方法提交相关配置并启动会话 * param captureSession * returns */ export async function startSession(captureSession: camera.CaptureSession): Promisevoid { try { await captureSession.commitConfig(); } catch (error) { let err error as BusinessError; console.error([camera test] Failed to commitConfig. error: ${JSON.stringify(err)}); } ​ try { await captureSession.start() } catch (error) { let err error as BusinessError; console.error([camera test] Failed to start. error: ${JSON.stringify(err)}); } } ​ export function getCameraInput(cameraDevice: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | null{ // 创建相机输入流 let cameraInput: camera.CameraInput | null null; try { cameraInput cameraManager.createCameraInput(cameraDevice); // 监听cameraInput错误信息 cameraInput.on(error, cameraDevice, (error: BusinessError) { console.info([camera test] Camera input error code: ${error.code}); }); } catch (error) { let err error as BusinessError; console.error([camera test] Failed to createCameraInput errorCode err.code); } ​ return cameraInput; } ​ /** * 通过getSupportedOutputCapability()方法获取当前设备支持的所有输出流 * 输出流在CameraOutputCapability中的各个profile字段中 * param cameraDevice * param cameraManager * returns */ export async function getSupportedOutputCapability(cameraDevice: camera.CameraDevice, cameraManager: camera.CameraManager, cameraInput: camera.CameraInput): Promisecamera.CameraOutputCapability | undefined { // 打开相机 await cameraInput.open(); // 获取相机设备支持的输出流能力 let cameraOutputCapability cameraManager.getSupportedOutputCapability(cameraDevice); if (!cameraOutputCapability) { console.error([camera test] cameraManager.getSupportedOutputCapability error); return undefined; } console.info([camera test] outputCapability: JSON.stringify(cameraOutputCapability)); return cameraOutputCapability; } ​ /** * 获取预览流 * param cameraManager * param cameraOutputCapability * param surfaceId * returns */ export function getPreviewOutput(cameraManager: camera.CameraManager, cameraOutputCapability: camera.CameraOutputCapability, surfaceId: string): camera.PreviewOutput | undefined { let previewProfilesArray: Arraycamera.Profile cameraOutputCapability.previewProfiles; let previewOutput: camera.PreviewOutput | undefined undefined; try { previewOutput cameraManager.createPreviewOutput(previewProfilesArray[0], surfaceId); } catch (error) { let err error as BusinessError; console.error([camera test] Failed to create the PreviewOutput instance. error code: err.code); } return previewOutput; } ​ export function setSessionCameraInput(captureSession: camera.CaptureSession, cameraInput: camera.CameraInput): void{ try { captureSession.addInput(cameraInput); } catch (error) { let err error as BusinessError; console.error([camera test] Failed to addInput. error: ${JSON.stringify(err)}); } } ​ export function setSessionPreviewOutput(captureSession: camera.CaptureSession, previewOutput: camera.PreviewOutput): void{ try { captureSession.addOutput(previewOutput); } catch (error) { let err error as BusinessError; console.error([camera test] Failed to add previewOutput. error: ${JSON.stringify(err)}); } }关键函数说明getCameraManager获取相机管理器实例getCameraDevices枚举设备支持的相机前置/后置getCameraInput创建相机输入流并监听错误事件getSupportedOutputCapability获取相机支持的输出能力需要先打开相机getPreviewOutput创建预览输出关键是将Surface ID传入会话管理beginConfig → addInput/addOutput → commitConfig → start欢迎大家加入开源鸿蒙跨平台开发者社区汇聚全球开发者提供清晰的贡献路径与激励体系你的每一行代码都可能成为产业升级的基石
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

网站被别的域名绑定网站建设文本

FaceFusion人脸替换结果如何通过图灵测试?在一段视频中,你看到某位演员正深情地念着台词。他的表情自然,眼神有光,连皮肤上的细微毛孔都清晰可见——但这个人,其实从未出演过这部影片。这是现代深度伪造(De…

张小明 2026/3/1 20:23:25 网站建设

建站公司学习手机wap网页设计

5个pk3DS高级技巧:打造专属宝可梦世界的秘密武器 【免费下载链接】pk3DS Pokmon (3DS) ROM Editor & Randomizer 项目地址: https://gitcode.com/gh_mirrors/pk/pk3DS pk3DS是一款功能强大的Pokmon 3DS ROM编辑器与随机化工具,专为宝可梦游戏…

张小明 2026/3/1 10:04:39 网站建设

永兴县网站建设哪家好怎么做产品推广平台

还在为WPS中无法高效管理文献引用而烦恼吗?每次写论文都要在多个软件间反复切换?WPS-Zotero插件的出现,彻底解决了Linux用户的这一痛点。这款开源工具让WPS Writer与Zotero实现无缝对接,为学术写作带来革命性体验。 【免费下载链接…

张小明 2026/3/2 11:33:29 网站建设

公司网站怎么弄怎么做门淘宝网站

YOLOv5目标检测快速上手指南 在智能制造、智能安防和无人系统日益普及的今天,实时目标检测已成为AI落地的核心能力之一。无论是产线上的缺陷识别,还是城市监控中的异常行为捕捉,开发者都希望用最短路径将模型部署到真实场景中。而YOLOv5正是…

张小明 2026/3/2 16:16:25 网站建设

建设网站的价格是多少钱介绍家乡的网页设计代码

快速体验 打开 InsCode(快马)平台 https://www.inscode.net输入框内输入如下内容: 开发一个电商产品3D展示动画生成器。功能需求:1. 上传产品3D模型自动生成旋转展示动画 2. 支持添加产品亮点标注动画 3. 可调整动画速度与视角 4. 一键生成产品拆解动画…

张小明 2025/12/27 0:43:05 网站建设

网课系统软件网站建设费用wordpress网站如何

告别闭源依赖!使用LobeChat搭建完全自主的AI对话系统 在企业开始将大模型深度融入业务流程的今天,一个现实问题正变得愈发棘手:我们是否真的愿意把所有客户咨询、内部知识甚至战略讨论,都通过API发送到第三方服务器上?…

张小明 2026/3/2 19:02:17 网站建设