Public Function saturation(ByVal img As Image, ByVal s As Single) As Image
Const lumR As Single = 0.3086
Const lumG As Single = 0.6094
Const lumB As Single = 0.082
Dim a As Single = (1.0 - s) * lumR + s
Dim b As Single = (1.0 - s) * lumR
Dim c As Single = (1.0 - s) * lumR
Dim d As Single = (1.0 - s) * lumG
Dim e As Single = (1.0 - s) * lumG + s
Dim f As Single = (1.0 - s) * lumG
Dim g As Single = (1.0 - s) * lumB
Dim h As Single = (1.0 - s) * lumB
Dim i As Single = (1.0 - s) * lumB + s
Dim cm As Drawing.Imaging.ColorMatrix = New Drawing.Imaging.ColorMatrix(New Single()() _
{New Single() {a, b, c, 0, 0}, _
New Single() {d, e, f, 0, 0}, _
New Single() {g, h, i, 0, 0}, _
New Single() {0, 0, 0, 1, 0}, _
New Single() {0, 0, 0, 0, 1}})
Return apply_cm(img, cm)
End Function
Public Function apply_cm(ByVal img As Image, ByVal cm As Drawing.Imaging.ColorMatrix) As Image
'return new image with given ImageAttributes set
Dim bm As Bitmap = New Bitmap(img.Width, img.Height)
Dim g As Graphics = Graphics.FromImage(bm)
Dim ia As New Drawing.Imaging.ImageAttributes
ia.SetColorMatrix(cm)
g.DrawImage(img, New Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia)
g.Dispose()
Return bm
End Function