Results 1 to 3 of 3

Thread: How to tint a bitmap... *Solved*

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    How to tint a bitmap... *Solved*

    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:
    1. Imports System.Drawing.Imaging
    2. Public Class Form1
    3.  
    4.     Dim bit As Bitmap = New Bitmap(My.Resources.test)
    5.  
    6.     Private Function TintBitmap(b As Bitmap, color As Color, intensity As Single) As Bitmap
    7.         Dim b2 As New Bitmap(b.Width, b.Height)
    8.  
    9.         Dim ia As New ImageAttributes
    10.  
    11.         Dim m As ColorMatrix
    12.         m = New ColorMatrix(New Single()() _
    13.             {New Single() {1, 0, 0, 0, 0}, _
    14.              New Single() {0, 1, 0, 0, 0}, _
    15.              New Single() {0, 0, 1, 0, 0}, _
    16.              New Single() {0, 0, 0, 1, 0}, _
    17.              New Single() {color.R / 255 * intensity, color.G / 255 * intensity, color.B / 255 * intensity, 0, 1}})
    18.  
    19.         ia.SetColorMatrix(m)
    20.         Dim g As Graphics = Graphics.FromImage(b2)
    21.         g.DrawImage(b, New Rectangle(0, 0, b.Width, b.Height), 0, 0, b.Width, b.Height, GraphicsUnit.Pixel, ia)
    22.         Return b2
    23.  
    24.     End Function
    25.  
    26.     Private Sub PictureBox1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
    27.         PictureBox1.Image = TintBitmap(bit, Color.Red, 0.5)
    28.     End Sub
    29. 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!
    Last edited by NinjaNic; Oct 20th, 2014 at 08:48 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width