所以我一直在尝试用矩阵来改变图像的对比度,这就是我想出的方法:
final defaultColorMatrix = const <double>[
1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0,
];
List<double> calculateContrastMatrix(double contrast) {
final m = List<double>.from(defaultColorMatrix);
m[0] = contrast;
m[6] = contrast;
m[12] = contrast;
m[5] = (1 - contrast) / 2;
m[10] = (1 - contrast) / 2;
m[15] = (1 - contrast) / 2;
return m;对比度和可调值在0和1之间
它给了我不太理想的结果
发布于 2021-04-05 23:39:17
我刚刚意识到最后一列不是m[5],m[10],m[15],而是m[4],m[9],m[14]。我忘记了dart的数组索引从0开始。
我还忘记了颤动矩阵中的最后一列没有归一化为0-255之间的期望值,因此正确的解决方案是:
List<double> calculateContrastMatrix(double contrast) {
final m = List<double>.from(defaultColorMatrix);
m[0] = contrast;
m[6] = contrast;
m[12] = contrast;
m[4] = ((1 - contrast) / 2) * 255;
m[9] = ((1 - contrast) / 2) * 255;
m[14] = ((1 - contrast) / 2) * 255;
return m;https://stackoverflow.com/questions/66954568
复制相似问题