椭圆形的颤振圆文件图像

Osa*_*mal 3 dart flutter

我想剪切从图像选择器插件中提取的图像,但该图像无法使用BoxDecoration.circle,因此我想用椭圆形剪切器将其剪切为圆形。如何实现呢?

Vin*_*ino 9

您还可以使用ClipOval来圈出图像。只需用ClipOval.

ClipOval(
  child: FileImage(_image)
),
Run Code Online (Sandbox Code Playgroud)


Vin*_*mar 6

您可以使用CircleAvatar小部件来显示获得的图像以使其成像circular

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),
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)


Uch*_*dim 6

如果你想使用 BoxDecoration.Circle,这就是你需要做的

                 Container(
                    width: 120.0,
                    height: 120.0,
                    decoration:  BoxDecoration(
                        shape: BoxShape.circle,
                        image: DecorationImage(
                            fit: BoxFit.fill,
                            image:  FileImage(_image)
                          )
                        )
                      ),
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助