Hello!
I'm trying out new things on VB, and now I want to know how to tint a bitmap image. I've googled it, and I've found this:
vb Code:
Imports System.Drawing.Imaging Public Class Form1 Dim bit As Bitmap = New Bitmap(My.Resources.test) Private Function TintBitmap(b As Bitmap, color As Color, intensity As Single) As Bitmap Dim b2 As New Bitmap(b.Width, b.Height) Dim ia As New ImageAttributes Dim m As ColorMatrix m = New ColorMatrix(New Single()() _ {New Single() {1, 0, 0, 0, 0}, _ New Single() {0, 1, 0, 0, 0}, _ New Single() {0, 0, 1, 0, 0}, _ New Single() {0, 0, 0, 1, 0}, _ New Single() {color.R / 255 * intensity, color.G / 255 * intensity, color.B / 255 * intensity, 0, 1}}) ia.SetColorMatrix(m) Dim g As Graphics = Graphics.FromImage(b2) g.DrawImage(b, New Rectangle(0, 0, b.Width, b.Height), 0, 0, b.Width, b.Height, GraphicsUnit.Pixel, ia) Return b2 End Function Private Sub PictureBox1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint PictureBox1.Image = TintBitmap(bit, Color.Red, 0.5) End Sub End Class
It works, but can someone please explain to me what this code means; what I am doing? What is a color matrix?
Thanks!




Reply With Quote
