如何在颤动中创建颜色矩阵? [英] How do I create a color matrix in flutter?

查看:92
本文介绍了如何在颤动中创建颜色矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用ColorFiltered小部件应用颜色饱和度矩阵,但不知道如何制作该矩阵.

I'm looking to use the ColorFiltered widget to apply a color saturation matrix but don't know how to make the matrix.

推荐答案

在我的情况下,我通过以下方式解决了该问题:

in my case i solved it following way:

class CustomSubFilters extends ColorFilter {
  CustomSubFilters.matrix(List<double> matrix) : super.matrix(matrix);

  ///defaults to unity matrix when s = 0;
  factory CustomSubFilters.saturate(double sat) {
    num x = 1 + sat;
    num lumR = 0.3086;
    num lumG = 0.6094;
    num lumB = 0.0820;

return CustomSubFilters.matrix(<double>[
  lumR * (1 - x) + x,
  lumG * (1 - x),
  lumB * (1 - x),
  0,
  0,
  lumR * (1 - x),
  lumG * (1 - x) + x,
  lumB * (1 - x),
  0,
  0,
  lumR * (1 - x),
  lumG * (1 - x),
  lumB * (1 - x) + x,
  0,
  0,
  0,
  0,
  0,
  1,
  0,
]);

}

当然,您可以灵活地实现该实现,只是不要忘记扩展ColorFilter类.

Of course you are flexible with the implementation just don't forget to extend the ColorFilter class.

这篇关于如何在颤动中创建颜色矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆