dart 如何在Flutter中向ArCore添加图像

4dc9hkyq  于 2023-06-03  发布在  Flutter
关注(0)|答案(1)|浏览(206)

基本上,我有一个ar应用程序使用ARCore插件。我想通过将其放置在某个矢量上来添加一个图像。然而,我所看到的例子并没有涵盖这一点。所以我去了文档,找到了一个图像类(下面的链接)。然而,我不明白我需要在每个字段中放入什么,因为它说的是字节和哈希,我甚至不确定这是正确的类。如果有人能帮上忙,那就太棒了!
友情链接:首页https://pub.dev/packages/arcore_flutter_plugin
主要文档:https://pub.dev/documentation/arcore_flutter_plugin/latest/arcore_flutter_plugin/arcore_flutter_plugin-library.html
ARCore映像类:https://pub.dev/documentation/arcore_flutter_plugin/latest/arcore_flutter_plugin/ArCoreImage-class.html

elcex8rz

elcex8rz1#

嘿,你可以像这样插入图片

import 'package:arcore_flutter_plugin/arcore_flutter_plugin.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(HelloWorld());
}

class HelloWorld extends StatefulWidget {
  @override
  _HelloWorldState createState() => _HelloWorldState();
}

class _HelloWorldState extends State<HelloWorld> {
  late ArCoreController arCoreController;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Hello World'),
        ),
        body: ArCoreView(
          onArCoreViewCreated: _onArCoreViewCreated,
        ),
      ),
    );
  }

  void _onArCoreViewCreated(ArCoreController controller) {
    arCoreController = controller;
    _addImage(arCoreController);
  }

  Future<Uint8List> getImageBytes(String imageName) async {
    final ByteData data = await rootBundle.load('assets/$imageName');
    return data.buffer.asUint8List();
  }

  void _addImage(ArCoreController controller) async {
    final imagebytes = await getImageBytes("harry.png");
    final node = ArCoreNode(
      image:ArCoreImage(bytes:imagebytes,width:50,height:50),
      position: vector.Vector3(-0.5, 0.5, -3.5),
    );
    controller.addArCoreNode(node);
  }

  @override
  void dispose() {
    arCoreController.dispose();
    super.dispose();
  }
}

相关问题