The method below, takes a colour matrix and applies it to the supplied image. There are a couple of things to note:
(1) It is not a function
(2) The same image is used to create the graphics object, and as the source of the DrawImage method.
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
I don't know if it's bad practice not to create another bitmap to render the final image into, but the strange thing is the method works fine for a colour balance adjustment (Matrix30, 31 and 32), but does nothing for an opacity adjustment (Matrix33).
What's going on?