改变颤振中图像的纵横比

问题描述:

我正在使用抖动,并且试图将图像的宽高比从4:3更改为16:9。我试过使用AspectRatio窗口小部件和FittedBox,但图像仍然保持4:3

I am using flutter and I am trying to change the aspect ratio of an image from 4:3 to 16:9. I have tried using the AspectRatio Widget and also using FittedBox but the image still remains 4:3

我试过使用AspectRatio,将Image上的fit道具更改为覆盖,适合并包含

I have tried using AspectRatio, changing the fit prop on the Image to cover, fit, and contain

Card(elevation: 3.0, child: Column(
children: <Widget>[Container(child:
AspectRatio(aspectRatio: 16.0 / 9.0, child: FittedBox(fit: 
BoxFit.contain,
child: Image(image: AssetImage('images/maggie.jpg')),),)
                                   )],


您需要使用 BoxFit.fill 来查看效果, BoxFit.cover 在裁剪图像时也显示相同的效果。也不需要 FittedBox

You need to use BoxFit.fill to see the effect, BoxFit.cover shows same effect with image cropped. And you also don't need FittedBox.

Card(
  elevation: 3.0,
  child: Column(
    children: <Widget>[
      Container(
        child: AspectRatio(
          aspectRatio: 16 / 9,
          child: Image(
            image: AssetImage('images/maggie.jpg'),
            fit: BoxFit.fill, // use this
          ),
        ),
      )
    ],
  ),
)