視頻中老師書寫的代碼可能存在功能實現上的錯誤或者粗心的漏洞
本來想寫在評論區的,發現有字數限制。
老師的視頻中書寫的代碼(源碼)中:
? ? ? ColorMatrix hueMatrix = new ColorMatrix();
? ? ? ? hueMatrix.setRotate(0, hue);
? ? ? ? hueMatrix.setRotate(1, hue);
? ? ? ? hueMatrix.setRotate(2, hue);
實際hueMatrix.setRotate(0, hue);和hueMatrix.setRotate(1, hue);是起不到作用的,真正起作用的是hueMatrix.setRotate(2, hue);,也就是幫助文檔里說的圍繞BLUE調色圈的調節(把SeekBar拉到頭和尾呈現的是純藍色)。
正確的寫法是和調節其他兩項的寫法是一樣的,要創建新的ColorMatrix對象然后進行postConcat操作。
? ? ? ColorMatrix hueMatrix0 = new ColorMatrix();
? ? ? ? hueMatrix0.setRotate(0, hue);
ColorMatrix hueMatrix1 = new ColorMatrix();
? ? ? ? hueMatrix1.setRotate(1, hue);
ColorMatrix hueMatrix2 = new ColorMatrix();
? ? ? ? hueMatrix2.setRotate(2, hue);
如果分別為其創建各自的SeekBar,就可以看到hueMatrix0的SeekBar拉到頭尾是R調色圈,hueMatrix1的SeekBar拉到頭尾是G調色圈,而hueMatrix2的SeekBar就和視頻里的一樣是B調色圈。
額...這算是挺久的視頻了,不知道還有沒有人和我一樣來回顧,沒有去翻看ColorMatrix類的源碼,不知道我說的是否完全正確,只是現象是這樣的,所以希望后面看到的人可以自己試一下我上面所說的。
2019-10-09
我敲代碼試了一下,存在一個整體和分顏色的色相變化。
只運行單獨一行,從程序效果上來說是這樣的變化。