Color: Red, Green, Blue, Hue, Saturation, Brightness, Sector : Color « 2D Graphics « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » 2D Graphics » Color 
17.26.16.Color: Red, Green, Blue, Hue, Saturation, Brightness, Sector
Color: Red, Green, Blue, Hue, Saturation, Brightness, Sector
' Quote from
'Visual Basic 2005 Cookbook Solutions for VB 2005 Programmers
'by Tim Patrick (Author), John Craig (Author)
'# Publisher: O'Reilly Media, Inc. (September 212006)
'# Language: English
'# ISBN-100596101775
'# ISBN-13978-0596101770



Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

public class ColorRGBSH
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class


Public Class Form1
    Private Sub RBG_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs_
            Handles ValueRed.Scroll, ValueGreen.Scroll, ValueBlue.Scroll
        Dim rgbColor As Color

        rgbColor = Color.FromArgb(0, ValueRed.Value, ValueGreen.Value, ValueBlue.Value)
        ValueHue.Value = CInt(rgbColor.GetHue())
        ValueSaturation.Value = CInt(rgbColor.GetSaturation() 100.0F)
        ValueBrightness.Value = CInt(rgbColor.GetBrightness() 100.0F)

        RefreshDisplay()
    End Sub

    Private Sub ValueHue_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs_
            Handles ValueHue.Scroll, ValueSaturation.Scroll, ValueBrightness.Scroll

        Dim useRed As Integer
        Dim useGreen As Integer
        Dim useBlue As Integer
        Dim useHue As Single
        Dim useSaturation As Single
        Dim useBrightness As Single
        Dim hueSector As Integer
        Dim factor As Single
        Dim target1 As Single
        Dim target2 As Single
        Dim target3 As Single

        useHue = CSng(ValueHue.Value)
        useSaturation = CSng(ValueSaturation.Value100.0F
        useBrightness = CSng(ValueBrightness.Value100.0F

        If (useSaturation = 0.0FThen
            useRed = CInt(useBrightness * 255)
            useGreen = useRed
            useBlue = useRed
        Else
            hueSector = CInt(useHue / 60.0F)
            factor = Math.Abs((useHue / 60.0F- CSng(hueSector))
            target1 = useBrightness * (- useSaturation)
            target2 = useBrightness * ((factor * useSaturation))
            target3 = useBrightness * (((- factor* useSaturation))

            Select Case hueSector
                Case 06
                    useRed = CInt(useBrightness * 255.0F)
                    useGreen = CInt(target3 * 255.0F)
                    useBlue = CInt(target1 * 255.0F)
                Case 1
                    useRed = CInt(target2 * 255.0F)
                    useGreen = CInt(useBrightness * 255.0F)
                    useBlue = CInt(target1 * 255.0F)
                Case 2
                    useRed = CInt(target1 * 255.0F)
                    useGreen = CInt(useBrightness * 255.0F)
                    useBlue = CInt(target3 * 255.0F)
                Case 3
                    useRed = CInt(target1 * 255.0F)
                    useGreen = CInt(target2 * 255.0F)
                    useBlue = CInt(useBrightness * 255.0F)
                Case 4
                    useRed = CInt(target3 * 255.0F)
                    useGreen = CInt(target1 * 255.0F)
                    useBlue = CInt(useBrightness * 255.0F)
                Case 5
                    useRed = CInt(useBrightness * 255.0F)
                    useGreen = CInt(target1 * 255.0F)
                    useBlue = CInt(target2 * 255.0F)
            End Select
        End If

        ValueRed.Value = useRed
        ValueGreen.Value = useGreen
        ValueBlue.Value = useBlue

        RefreshDisplay()
    End Sub

    Private Sub RefreshDisplay()
        NumberRed.Text = CStr(ValueRed.Value)
        NumberGreen.Text = CStr(ValueGreen.Value)
        NumberBlue.Text = CStr(ValueBlue.Value)
        NumberHue.Text = CStr(ValueHue.Value)
        NumberSaturation.Text = Format(CDec(ValueSaturation.Value100@, "0.00")
        NumberBrightness.Text = Format(CDec(ValueBrightness.Value100@, "0.00")

        ShowColor.BackColor = Color.FromArgb(255, ValueRed.Value, _
            ValueGreen.Value, ValueBlue.Value)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgsHandles MyBase.Load
        RBG_Scroll(ValueRed, New Windows.Forms.ScrollEventArgs(ScrollEventType.EndScroll, 0))
    End Sub
End Class


<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.ShowColor = New System.Windows.Forms.PictureBox
        Me.LabelRed = New System.Windows.Forms.Label
        Me.ValueRed = New System.Windows.Forms.HScrollBar
        Me.NumberRed = New System.Windows.Forms.Label
        Me.NumberGreen = New System.Windows.Forms.Label
        Me.ValueGreen = New System.Windows.Forms.HScrollBar
        Me.LabelGreen = New System.Windows.Forms.Label
        Me.NumberBlue = New System.Windows.Forms.Label
        Me.ValueBlue = New System.Windows.Forms.HScrollBar
        Me.LabelBlue = New System.Windows.Forms.Label
        Me.NumberBrightness = New System.Windows.Forms.Label
        Me.ValueBrightness = New System.Windows.Forms.HScrollBar
        Me.LabelBrightness = New System.Windows.Forms.Label
        Me.NumberSaturation = New System.Windows.Forms.Label
        Me.ValueSaturation = New System.Windows.Forms.HScrollBar
        Me.LabelSaturation = New System.Windows.Forms.Label
        Me.NumberHue = New System.Windows.Forms.Label
        Me.ValueHue = New System.Windows.Forms.HScrollBar
        Me.LabelHue = New System.Windows.Forms.Label
        CType(Me.ShowColor, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'ShowColor
        '
        Me.ShowColor.BackColor = System.Drawing.SystemColors.Control
        Me.ShowColor.Location = New System.Drawing.Point(880)
        Me.ShowColor.Name = "ShowColor"
        Me.ShowColor.Size = New System.Drawing.Size(33632)
        Me.ShowColor.TabIndex = 1
        Me.ShowColor.TabStop = False
        '
        'LabelRed
        '
        Me.LabelRed.AutoSize = True
        Me.LabelRed.Location = New System.Drawing.Point(810)
        Me.LabelRed.Name = "LabelRed"
        Me.LabelRed.Size = New System.Drawing.Size(2713)
        Me.LabelRed.TabIndex = 0
        Me.LabelRed.Text = "Red"
        '
        'ValueRed
        '
        Me.ValueRed.LargeChange = 1
        Me.ValueRed.Location = New System.Drawing.Point(728)
        Me.ValueRed.Maximum = 255
        Me.ValueRed.Name = "ValueRed"
        Me.ValueRed.Size = New System.Drawing.Size(22416)
        Me.ValueRed.TabIndex = 1
        '
        'NumberRed
        '
        Me.NumberRed.AutoSize = True
        Me.NumberRed.Location = New System.Drawing.Point(30410)
        Me.NumberRed.Name = "NumberRed"
        Me.NumberRed.Size = New System.Drawing.Size(1313)
        Me.NumberRed.TabIndex = 2
        Me.NumberRed.Text = "0"
        '
        'NumberGreen
        '
        Me.NumberGreen.AutoSize = True
        Me.NumberGreen.Location = New System.Drawing.Point(30434)
        Me.NumberGreen.Name = "NumberGreen"
        Me.NumberGreen.Size = New System.Drawing.Size(1313)
        Me.NumberGreen.TabIndex = 5
        Me.NumberGreen.Text = "0"
        '
        'ValueGreen
        '
        Me.ValueGreen.LargeChange = 1
        Me.ValueGreen.Location = New System.Drawing.Point(7232)
        Me.ValueGreen.Maximum = 255
        Me.ValueGreen.Name = "ValueGreen"
        Me.ValueGreen.Size = New System.Drawing.Size(22416)
        Me.ValueGreen.TabIndex = 4
        '
        'LabelGreen
        '
        Me.LabelGreen.AutoSize = True
        Me.LabelGreen.Location = New System.Drawing.Point(834)
        Me.LabelGreen.Name = "LabelGreen"
        Me.LabelGreen.Size = New System.Drawing.Size(3613)
        Me.LabelGreen.TabIndex = 3
        Me.LabelGreen.Text = "Green"
        '
        'NumberBlue
        '
        Me.NumberBlue.AutoSize = True
        Me.NumberBlue.Location = New System.Drawing.Point(30458)
        Me.NumberBlue.Name = "NumberBlue"
        Me.NumberBlue.Size = New System.Drawing.Size(1313)
        Me.NumberBlue.TabIndex = 8
        Me.NumberBlue.Text = "0"
        '
        'ValueBlue
        '
        Me.ValueBlue.LargeChange = 1
        Me.ValueBlue.Location = New System.Drawing.Point(7256)
        Me.ValueBlue.Maximum = 255
        Me.ValueBlue.Name = "ValueBlue"
        Me.ValueBlue.Size = New System.Drawing.Size(22416)
        Me.ValueBlue.TabIndex = 7
        '
        'LabelBlue
        '
        Me.LabelBlue.AutoSize = True
        Me.LabelBlue.Location = New System.Drawing.Point(858)
        Me.LabelBlue.Name = "LabelBlue"
        Me.LabelBlue.Size = New System.Drawing.Size(2813)
        Me.LabelBlue.TabIndex = 6
        Me.LabelBlue.Text = "Blue"
        '
        'NumberBrightness
        '
        Me.NumberBrightness.AutoSize = True
        Me.NumberBrightness.Location = New System.Drawing.Point(304170)
        Me.NumberBrightness.Name = "NumberBrightness"
        Me.NumberBrightness.Size = New System.Drawing.Size(1313)
        Me.NumberBrightness.TabIndex = 17
        Me.NumberBrightness.Text = "0"
        '
        'ValueBrightness
        '
        Me.ValueBrightness.LargeChange = 1
        Me.ValueBrightness.Location = New System.Drawing.Point(72168)
        Me.ValueBrightness.Name = "ValueBrightness"
        Me.ValueBrightness.Size = New System.Drawing.Size(22416)
        Me.ValueBrightness.TabIndex = 16
        '
        'LabelBrightness
        '
        Me.LabelBrightness.AutoSize = True
        Me.LabelBrightness.Location = New System.Drawing.Point(8170)
        Me.LabelBrightness.Name = "LabelBrightness"
        Me.LabelBrightness.Size = New System.Drawing.Size(5613)
        Me.LabelBrightness.TabIndex = 15
        Me.LabelBrightness.Text = "Brightness"
        '
        'NumberSaturation
        '
        Me.NumberSaturation.AutoSize = True
        Me.NumberSaturation.Location = New System.Drawing.Point(304146)
        Me.NumberSaturation.Name = "NumberSaturation"
        Me.NumberSaturation.Size = New System.Drawing.Size(1313)
        Me.NumberSaturation.TabIndex = 14
        Me.NumberSaturation.Text = "0"
        '
        'ValueSaturation
        '
        Me.ValueSaturation.LargeChange = 1
        Me.ValueSaturation.Location = New System.Drawing.Point(72144)
        Me.ValueSaturation.Name = "ValueSaturation"
        Me.ValueSaturation.Size = New System.Drawing.Size(22416)
        Me.ValueSaturation.TabIndex = 13
        '
        'LabelSaturation
        '
        Me.LabelSaturation.AutoSize = True
        Me.LabelSaturation.Location = New System.Drawing.Point(8146)
        Me.LabelSaturation.Name = "LabelSaturation"
        Me.LabelSaturation.Size = New System.Drawing.Size(5513)
        Me.LabelSaturation.TabIndex = 12
        Me.LabelSaturation.Text = "Saturation"
        '
        'NumberHue
        '
        Me.NumberHue.AutoSize = True
        Me.NumberHue.Location = New System.Drawing.Point(304122)
        Me.NumberHue.Name = "NumberHue"
        Me.NumberHue.Size = New System.Drawing.Size(1313)
        Me.NumberHue.TabIndex = 11
        Me.NumberHue.Text = "0"
        '
        'ValueHue
        '
        Me.ValueHue.LargeChange = 1
        Me.ValueHue.Location = New System.Drawing.Point(72120)
        Me.ValueHue.Maximum = 360
        Me.ValueHue.Name = "ValueHue"
        Me.ValueHue.Size = New System.Drawing.Size(22416)
        Me.ValueHue.TabIndex = 10
        '
        'LabelHue
        '
        Me.LabelHue.AutoSize = True
        Me.LabelHue.Location = New System.Drawing.Point(8122)
        Me.LabelHue.Name = "LabelHue"
        Me.LabelHue.Size = New System.Drawing.Size(2713)
        Me.LabelHue.TabIndex = 9
        Me.LabelHue.Text = "Hue"
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(354195)
        Me.Controls.Add(Me.NumberBrightness)
        Me.Controls.Add(Me.ValueBrightness)
        Me.Controls.Add(Me.LabelBrightness)
        Me.Controls.Add(Me.NumberSaturation)
        Me.Controls.Add(Me.ValueSaturation)
        Me.Controls.Add(Me.LabelSaturation)
        Me.Controls.Add(Me.NumberHue)
        Me.Controls.Add(Me.ValueHue)
        Me.Controls.Add(Me.LabelHue)
        Me.Controls.Add(Me.NumberBlue)
        Me.Controls.Add(Me.ValueBlue)
        Me.Controls.Add(Me.LabelBlue)
        Me.Controls.Add(Me.NumberGreen)
        Me.Controls.Add(Me.ValueGreen)
        Me.Controls.Add(Me.LabelGreen)
        Me.Controls.Add(Me.NumberRed)
        Me.Controls.Add(Me.ValueRed)
        Me.Controls.Add(Me.LabelRed)
        Me.Controls.Add(Me.ShowColor)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Me.Name = "Form1"
        Me.Text = "RBG and HSV/HSB"
        CType(Me.ShowColor, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents ShowColor As System.Windows.Forms.PictureBox
    Friend WithEvents LabelRed As System.Windows.Forms.Label
    Friend WithEvents ValueRed As System.Windows.Forms.HScrollBar
    Friend WithEvents NumberRed As System.Windows.Forms.Label
    Friend WithEvents NumberGreen As System.Windows.Forms.Label
    Friend WithEvents ValueGreen As System.Windows.Forms.HScrollBar
    Friend WithEvents LabelGreen As System.Windows.Forms.Label
    Friend WithEvents NumberBlue As System.Windows.Forms.Label
    Friend WithEvents ValueBlue As System.Windows.Forms.HScrollBar
    Friend WithEvents LabelBlue As System.Windows.Forms.Label
    Friend WithEvents NumberBrightness As System.Windows.Forms.Label
    Friend WithEvents ValueBrightness As System.Windows.Forms.HScrollBar
    Friend WithEvents LabelBrightness As System.Windows.Forms.Label
    Friend WithEvents NumberSaturation As System.Windows.Forms.Label
    Friend WithEvents ValueSaturation As System.Windows.Forms.HScrollBar
    Friend WithEvents LabelSaturation As System.Windows.Forms.Label
    Friend WithEvents NumberHue As System.Windows.Forms.Label
    Friend WithEvents ValueHue As System.Windows.Forms.HScrollBar
    Friend WithEvents LabelHue As System.Windows.Forms.Label

End Class
17.26.Color
17.26.1.KnownColor.ActiveBorder
17.26.2.ColorTranslator.FromHtml('#0000ff')
17.26.3.Color.FromNameColor.FromName
17.26.4.Color.FromArgbColor.FromArgb
17.26.5.Create Color from R G B values
17.26.6.Create Color from R G B value and Alpha
17.26.7.Create Color from SystemColors
17.26.8.Color AlphaColor Alpha
17.26.9.Convert color from string (FF00FF)Convert color from string (FF00FF)
17.26.10.Color.FromWin32Color.FromWin32
17.26.11.Color.FromHtmlColor.FromHtml
17.26.12.Get Color from static fields defined in ColorGet Color from static fields defined in Color
17.26.13.Color.FromArgb(-1090518785)Color.FromArgb(-1090518785)
17.26.14.Get Hue, Saturation, Brightness from a colorGet Hue, Saturation, Brightness from a color
17.26.15.Using different colors in Visual BasicUsing different colors in Visual Basic
17.26.16.Color: Red, Green, Blue, Hue, Saturation, Brightness, SectorColor: Red, Green, Blue, Hue, Saturation, Brightness, Sector
17.26.17.System.Drawing.ColorTranslator.FromOleSystem.Drawing.ColorTranslator.FromOle
17.26.18.Transparent ColorTransparent Color
17.26.19.Alpha blending colorAlpha blending color
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.