Dim GFX As Graphics, Bmp As Bitmap, ColorMx As Imaging.ColorMatrix, Ia As Imaging.ImageAttributes Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load GFX = Me.CreateGraphics() ''Draws to the form. Bmp = New Bitmap("C:\pachinko.gif") 'Picture of a flying pachinko ball weapon. Ia = New Imaging.ImageAttributes 'Can set color matrices for us. End Sub Private Sub Btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn4.Click ColorMx = New Imaging.ColorMatrix(New Single()() { _ New Single() {1.0F, 0.0F, 0.0F, 0.0F, 0.0F}, _ New Single() {0.0F, 1.0F, 0.0F, 0.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 1.0F, 0.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 0.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 0.4F, 1.0F}}) Ia.SetColorMatrix(ColorMx) GFX.DrawImage(Bmp, New Rectangle(64, 0, Bmp.Width, Bmp.Height), 0, 0, Bmp.Width, Bmp.Height, GraphicsUnit.Pixel, Ia) End Sub |
Dim GFX As Graphics, Bmp As Bitmap, ColorMx As Imaging.ColorMatrix, Ia As Imaging.ImageAttributes Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load GFX = Me.CreateGraphics() ''Draws to the form. Bmp = New Bitmap("C:\pachinko.gif") 'Picture of a flying pachinko ball weapon. Ia = New Imaging.ImageAttributes 'Can set color matrices for us. End Sub Private Sub Btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn6.Click ColorMx = New Imaging.ColorMatrix(New Single()() { _ New Single() {0.3F, 0.3F, 0.3F, 0.0F, 0.0F}, _ New Single() {0.58F, 0.58F, 0.58F, 0.0F, 0.0F}, _ New Single() {0.11F, 0.11F, 0.11F, 0.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 1.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 0.0F, 0.0F}}) Ia.SetColorMatrix(ColorMx) GFX.DrawImage(Bmp, New Rectangle(64, 0, Bmp.Width, Bmp.Height), 0, 0, Bmp.Width, Bmp.Height, GraphicsUnit.Pixel, Ia) End Sub |
Dim GFX As Graphics, Bmp As Bitmap, ColorMx As Imaging.ColorMatrix, Ia As Imaging.ImageAttributes Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load GFX = Me.CreateGraphics() ''Draws to the form. Bmp = New Bitmap("C:\pachinko.gif") 'Picture of a flying pachinko ball weapon. Ia = New Imaging.ImageAttributes 'Can set color matrices for us. End Sub Private Sub Btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn5.Click ColorMx = New Imaging.ColorMatrix(New Single()() { _ New Single() {1.0F, 0.0F, 0.0F, 0.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 1.0F, 0.0F, 0.0F}, _ New Single() {0.0F, 1.0F, 0.0F, 0.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 1.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 0.0F, 1.0F}}) Ia.SetColorMatrix(ColorMx) GFX.DrawImage(Bmp, New Rectangle(64, 0, Bmp.Width, Bmp.Height), 0, 0, Bmp.Width, Bmp.Height, GraphicsUnit.Pixel, Ia) End Sub |
Dim GFX As Graphics, Bmp As Bitmap, ColorMx As Imaging.ColorMatrix, Ia As Imaging.ImageAttributes Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load GFX = Me.CreateGraphics() ''Draws to the form. Bmp = New Bitmap("C:\pachinko.gif") 'Picture of a flying pachinko ball weapon. Ia = New Imaging.ImageAttributes 'Can set color matrices for us. End Sub Private Sub Btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn6.Click ColorMx = New Imaging.ColorMatrix(New Single()() { _ New Single() {0.0F, 0.3F, 0.0F, 0.0F, 0.0F}, _ New Single() {0.58F, 0.58F, 0.58F, 0.0F, 0.0F}, _ New Single() {0.0F, 0.11F, 0.0F, 0.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 1.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 0.0F, 1.0F}}) Ia.SetColorMatrix(ColorMx) GFX.DrawImage(Bmp, New Rectangle(64, 0, Bmp.Width, Bmp.Height), 0, 0, Bmp.Width, Bmp.Height, GraphicsUnit.Pixel, Ia) End Sub |
ColorMx = New Imaging.ColorMatrix(New Single()() { _ New Single() {0.3F * 0F, 0.3F * 0F, 0.3F * 1F, 0.0F, 0.0F}, _ New Single() {0.58F * 0F, 0.58F * 0F, 0.58F * 1F, 0.0F, 0.0F}, _ New Single() {0.11F * 0F, 0.11F * 0F, 0.11F * 1F, 0.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 1.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 0.0F, 1.0F}}) 'or (simplified) ColorMx = New Imaging.ColorMatrix(New Single()() { _ New Single() {0.0F, 0.0F, 0.3F, 0.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.58F, 0.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.11F, 0.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 1.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 0.0F, 1.0F}}) |
ColorMx = New Imaging.ColorMatrix(New Single()() { _ New Single() {0.3F * 0F, 0.3F * 1F, 0.3F * 0F, 0.0F, 0.0F}, _ New Single() {0.58F * 0F, 0.58F * 1F, 0.58F * 0F, 0.0F, 0.0F}, _ New Single() {0.11F * 0F, 0.11F * 1F, 0.11F * 0F, 0.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 1.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 0.0F, 1.0F}}) 'or (simplified) ColorMx = New Imaging.ColorMatrix(New Single()() { _ New Single() {0.0F, 0.3F, 0.0F, 0.0F, 0.0F}, _ New Single() {0.0F, 0.59F, 0.0F, 0.0F, 0.0F}, _ New Single() {0.0F, 0.11F, 0.0F, 0.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 1.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 0.0F, 1.0F}}) |
Private Sub Btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn6.Click Dim C As Color, Rc, Gc, Bc As Single 'C is the color that our picture will be scaled to. C = Color.Red Rc = C.R / 255.0F Gc = C.G / 255.0F Bc = C.B / 255.0F 'All values must be divided by 255 by virtue of the color matrix. ColorMx = New Imaging.ColorMatrix(New Single()() { _ New Single() {0.3F * Rc, 0.3F * Gc, 0.3F * Bc, 0.0F, 0.0F}, _ New Single() {0.59F * Rc, 0.59F * Gc, 0.59F * Bc, 0.0F, 0.0F}, _ New Single() {0.11F * Rc, 0.11F * Gc, 0.11F * Bc, 0.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 1.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 0.0F, 1.0F}}) 'R multiplies the first column, G the second, and B the third. Ia.SetColorMatrix(ColorMx) GFX.DrawImage(Bmp, New Rectangle(64, 0, Bmp.Width, Bmp.Height), 0, 0, Bmp.Width, Bmp.Height, GraphicsUnit.Pixel, Ia) End Sub |
Private Sub Btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn6.Click Dim C As Color, Rc, Gc, Bc As Single 'C is the color that our picture will be scaled to. C = Color.SandyBrown Rc = C.R / 128.0F Gc = C.G / 128.0F Bc = C.B / 128.0F 'All values must be divided by 255 by virtue of the color matrix. ColorMx = New Imaging.ColorMatrix(New Single()() { _ New Single() {0.3F * Rc, 0.3F * Gc, 0.3F * Bc, 0.0F, 0.0F}, _ New Single() {0.59F * Rc, 0.59F * Gc, 0.59F * Bc, 0.0F, 0.0F}, _ New Single() {0.11F * Rc, 0.11F * Gc, 0.11F * Bc, 0.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 1.0F, 0.0F}, _ New Single() {0.0F, 0.0F, 0.0F, 0.0F, 1.0F}}) 'R multiplies the first column, G the second, and B the third. Ia.SetColorMatrix(ColorMx) GFX.DrawImage(Bmp, New Rectangle(64, 0, Bmp.Width, Bmp.Height), 0, 0, Bmp.Width, Bmp.Height, GraphicsUnit.Pixel, Ia) 'Now this REALLY looks like an antique picture! End Sub |
Be warned, Color.White will give you a really bright grayscale sunlight. Have fun with your color matrix like I did.