栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Flutter应用中是否有用于图像编辑器的API。我需要在图像中添加文字

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Flutter应用中是否有用于图像编辑器的API。我需要在图像中添加文字

您应该使用
RepaintBoundary 将其捕获为小部件并使用

覆盖小部件。

看一下这段代码,如何将小部件捕获为图像。

import 'dart:async';import 'dart:convert';import 'dart:typed_data';import 'dart:ui' as ui;import 'package:flutter/material.dart';import 'package:flutter/rendering.dart';void main() => runApp(new MyApp());class MyApp extends StatelessWidget {  @override  Widget build(BuildContext context) {    return new MaterialApp(      title: 'Flutter Demo',      theme: new ThemeData(        primarySwatch: Colors.blue,      ),      home: new MyHomePage(),    );  }}class MyHomePage extends StatefulWidget {  @override  _MyHomePageState createState() => new _MyHomePageState();}class _MyHomePageState extends State<MyHomePage> {  GlobalKey _globalKey = new GlobalKey();  bool inside = false;  Uint8List imageInMemory;  Future<Uint8List> _capturePng() async {    try {      print('inside');      inside = true;      RenderRepaintBoundary boundary =      _globalKey.currentContext.findRenderObject();      ui.Image image = await boundary.toImage(pixelRatio: 3.0);      ByteData byteData =      await image.toByteData(format: ui.ImageByteFormat.png);      Uint8List pngBytes = byteData.buffer.asUint8List();//      String bs64 = base64Enpre(pngBytes);//      print(pngBytes);//      print(bs64);      print('png done');      setState(() {        imageInMemory = pngBytes;        inside = false;      });      return pngBytes;    } catch (e) {      print(e);    }  }  @override  Widget build(BuildContext context) {    return RepaintBoundary(      key: _globalKey,      child: new Scaffold(          appBar: new AppBar( title: new Text('Widget To Image demo'),          ),          body: SingleChildScrollView( child: Center(   child: new Column(     mainAxisAlignment: MainAxisAlignment.center,     children: <Widget>[       new Text(         'click the button below to capture image',       ),       new RaisedButton(         child: Text('capture Image'),         onPressed: _capturePng,       ),       inside ? CircularProgressIndicator():       imageInMemory != null? Container(child: Image.memory(imageInMemory),margin: EdgeInsets.all(10)): Container(),     ],   ), ),          )),    );  }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/393555.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号