gpt4 book ai didi

dart - 带有剪辑椭圆的 flutter 圆形文件图像

转载 作者:IT老高 更新时间:2023-10-28 12:44:10 26 4
gpt4 key购买 nike

我想剪裁从图像选择器插件中提取的图像,但它不适用于 BoxDecoration.circle ,所以我想用椭圆剪裁器将其剪裁为圆形。如何实现?

最佳答案

您可以使用CircleAvatar小部件显示获取的图像,使其圆形

import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';

void main() => runApp(new MaterialApp(debugShowCheckedModeBanner: false, home: new MyApp()));

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
File _image;

Future getImage() async {
var image = await ImagePicker.pickImage(source: ImageSource.camera);

setState(() {
_image = image;
});
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Home'),
),
body: new Center(
child: _image == null
? new Text('No image selected.')
: new CircleAvatar(backgroundImage: new FileImage(_image), radius: 200.0,),
),
floatingActionButton: new FloatingActionButton(
onPressed: getImage,
tooltip: 'Pick Image',
child: new Icon(Icons.add_a_photo),
),
);
}
}

关于dart - 带有剪辑椭圆的 flutter 圆形文件图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50603767/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com