下面的方法采用颜色矩阵并将其应用于提供的图像。有几点需要注意:
(1) 它不是函数
(2) 相同的图像用于创建图形对象,并作为 DrawImage 方法的源。
Public Sub ApplyMatrixToImage(ByVal matrix As ColorMatrix, ByVal image As Image)
Using atts As New ImageAttributes
atts.SetColorMatrix(matrix)
Using g As Graphics = Graphics.FromImage(image)
Dim width As Integer = image.Width
Dim height As Integer = image.Height
Dim rect As New Rectangle(0, 0, width, height)
g.DrawImage(image, rect, 0, 0, width, height, GraphicsUnit.Pixel, atts)
End Using
End Using
End Sub
我不知道不创建另一个位图来渲染最终图像是否是不好的做法,但奇怪的是该方法适用于色彩平衡调整(Matrix30、31 和 32),但对不透明度调整没有任何作用(矩阵 33)。
这是怎么回事?