我想裁剪一个CameraPreview
小部件,这样我只能得到我想切割它的确切尺寸和位置。
目前我可以使用ClipRect
剪辑它,但是我得到了这个黑色区域,其中小部件被剪掉了我要删除的部分(请参阅下面的替换图片)
让我们说我们有这样的小部件
--------------
|88888888888888|
|88888888888888|
|88888888888888|
|88888888888888|
|88888888888888|
|88888888888888|
--------------
我需要裁剪小部件,(不是剪辑)
--------------
| |
| |
| 888 | -----
| 888 | | 888 |
| 888 | | 888 |
| | | 888 |
-------------- -----
CLIPPING CROPPING
任何人都可以帮我修剪小部件吗?
试试这个
final Size size = controller.value.size;
return ClipRect(
child: OverflowBox(
maxWidth: double.infinity,
maxHeight: double.infinity,
alignment: Alignment.center,
child: FittedBox(
fit: BoxFit.cover,
alignment: Alignment.center,
child: new Container(
width: size.width,
height: size.height,
child: CameraPreview(controller)
)
)
)
);
没关系,我设法自己解决了它,感觉像颤抖的框架以神秘的方式工作,直到我想出来
return Container( // just a parent
child: Align( // important
alignment: Alignment.center,
child: Container( // just a parent
width: some_width,
height: some_height,
child: SizedBox(
width: width, // final width of cropped portion
height: width, // final height of cropped portion
child: OverflowBox(
alignment: Alignment(-1,-1), // gives you top left portion of the size above, (1,1) gives bottom right, right direction is positive x, downward direction is positive y, see about Alignment on flutter docs for more details
maxWidth: double.infinity,
maxHeight: double.infinity,
child: Container(
width: width,
height: width,
child: ClipRect(
clipper: RectClipper(i, width / 4),// this is a custom clipper i made of type CustomClipper<Rect>
child: CameraPreview(controller),
),
),
),
),
),
),
);