flutter - 如何阻止模糊滤镜对模糊图像周围的颜色进行采样?
问题描述
我有一个演示小部件,如下所示:
class BlurDemo extends StatelessWidget {
BlurDemo({Key key}) : super(key: key);
final String imageUrl =
'https://dogtime.com/assets/uploads/2018/10/puppies-cover-1280x720.jpg';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Blur Demo'),
),
backgroundColor: Colors.black,
body: Center(
child: SizedBox(
width: 250,
height: 250,
child: FittedBox(
fit: BoxFit.cover,
child: Stack(children: [
Image.network(imageUrl),
Positioned.fill(
child: ClipRRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 20.0, sigmaY: 20.0),
child: Container(color: Colors.black.withAlpha(0))),
))])))));}}
当前效果:
所需效果(样机):
如果您查看“当前效果”图像中照片的边缘,您会看到变暗效果。模糊过滤器对图像周围的像素进行采样,即使这些像素位于剪辑矩形之外。在这个演示中,图像被裁剪并且有更多的周围像素可以被采样以获得模糊效果。即使它没有被裁剪,最好将效果钳制到 cliprect 的内容中并且不让周围的颜色渗入。
解决方案
ethanblake4 能够在 GitHub 上回答这个问题:https ://github.com/flutter/flutter/issues/61891 。
答案是使用ImageFiltered而不是 BackdropFilter。
推荐阅读
- python - 循环渲染的 Django 模板查询花费了太多时间
- ubuntu-16.04 - 传输 3.0 更新 (Ubuntu 16.04) - 使用错误的设置文件夹
- javascript - 如何根据用户先前的输入更改选择哪个选项
- vb.net - 如何防止我的 VB 应用程序崩溃
- python-3.x - python:试图在getter中设置值,结果对象没有属性
- javascript - 如何改变 Javascript/Html 画布图像的色调
- c++ - 在 xcode 上使用 stdlib.h
- electron - 在 Electron 中使用“另存为”对话框创建和保存文本文件
- python - 我无法在win10上安装tensorflow
- actions-on-google - 构建后找不到 Google 本地执行的节点/Web 子目录