首页 > 解决方案 > Using nearest neighbour interpolation for flutter image

问题描述

How do I get flutter to resize my Image widgets using nearest neighbour interpolation if the size of the widget is not the same as the asset size?

class PlayContainer extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Color.fromARGB(255, 0, 110, 255),
      child: SafeArea(
        child: Image(
          fit: BoxFit.contain,
          image: AssetImage("assets/knight.png")
        )
      )
    );
  }
}

This resizes the image correctly, but it is blurry due to the bilinear interpolation used to resize it.

Based on the source seems to be rather hard coded?

标签: flutter

解决方案


多亏了这个拉取请求,这现在可以在主分支中实现:

我添加了在图像上设置 filterQuality 的可能性。这是硬编码的。
先前硬编码的值被设置为默认参数。

某些图像在没有滤镜质量(如像素艺术)的情况下缩放时看起来更好。这就是我添加参数的原因。


推荐阅读