Get color component

Can anyone know how to convert these into VB.NET language??
Thanks

private static byte GetColorComponent(Color pixelColor, int colorComponent){
byte returnValue = 0;
switch(colorComponent){
case 0:
returnValue = pixelColor.R;
break;
case 1:
returnValue = pixelColor.G;
break;
case 2:
returnValue = pixelColor.B;
break;
}
return returnValue;
}

Comments

  • hey i got this link which converts vb.net code to c# may be u can find onw which converts vice versa
    http://www.elegancetech.com/CSVB.aspx
  • : Can anyone know how to convert these into VB.NET language??
    : Thanks
    :
    : private static byte GetColorComponent(Color pixelColor, int colorComponent){
    : byte returnValue = 0;
    : switch(colorComponent){
    : case 0:
    : returnValue = pixelColor.R;
    : break;
    : case 1:
    : returnValue = pixelColor.G;
    : break;
    : case 2:
    : returnValue = pixelColor.B;
    : break;
    : }
    : return returnValue;
    : }
    :

    Try the following example from the help files details of the>

    To Argb function>

    Color.ToArgb MethodSee Also
    Color Structure | Color Members | System.Drawing Namespace | Color Members (Visual J# Syntax) | Managed Extensions for C++ Programming
    Requirements
    Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
    Language

    Visual Basic

    Show All
    Gets the 32-bit ARGB value of this Color structure.

    [Visual Basic]
    Public Function ToArgb() As Integer

    Return Value
    The 32-bit ARGB value of this Color structure.

    Remarks
    The byte-ordering of the 32-bit ARGB value is AARRGGBB. The most significant byte (MSB), represented by AA, is the alpha component value. The second, third, and fourth bytes, represented by RR, GG, and BB, respectively, are the color components red, green, and blue, respectively. For example, suppose that a color is created from the four component values. The ToArgb method can be used to obtain the 32-bit ARGB value as follows:

    Example
    [Visual Basic, C#] The following example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. The code performs the following actions:

    Iterates through the KnownColor enumeration elements to find all known colors that have a nonzero green component and a zero-value red component, and that are not system colors.
    During each iteration: saves the KnownColor element, if it matches the criteria, in an array.
    Uses a brush to paint rectangles.
    [Visual Basic, C#] Each of the rectangles is painted a KnownColor that matches the criteria stated in the first step. The name of the KnownColor and its component values are also displayed.

    [Visual Basic, C#] This example displays certain known colors, the names of the colors, and their four component values. Use of the ToArgb method is a preliminary step to displaying the component values.

    [Visual Basic]
    Public Sub ToArgbToStringExample(e As PaintEventArgs)
    Dim g As Graphics = e.Graphics
    ' Color structure used for temporary storage.
    Dim someColor As Color = Color.FromArgb(0)
    ' Array to store KnownColor values that match the criteria.
    Dim colorMatches(167) As KnownColor
    Dim count As Integer = 0 ' number of matches found
    ' Iterate through KnownColor enums to find all corresponding colors
    ' that have a non-zero green component and zero-valued red
    ' component and that are not system colors.
    Dim enumValue As KnownColor
    For enumValue = 0 To KnownColor.YellowGreen
    someColor = Color.FromKnownColor(enumValue)
    If someColor.G <> 0 And someColor.R = 0 And _
    Not someColor.IsSystemColor Then
    colorMatches(count) = enumValue
    count += 1
    End If
    Next enumValue
    Dim myBrush1 As New SolidBrush(someColor)
    Dim myFont As New Font("Arial", 9)
    Dim x As Integer = 40
    Dim y As Integer = 40
    ' Iterate through the matches found and display each color that
    ' corresponds with the enum value in the array. Also display the
    ' name of the KnownColor and the ARGB components.
    Dim i As Integer
    For i = 0 To count - 1
    ' Display the color.
    someColor = Color.FromKnownColor(colorMatches(i))
    myBrush1.Color = someColor
    g.FillRectangle(myBrush1, x, y, 50, 30)
    ' Display KnownColor name and four component values. To display
    ' component values: Use the ToArgb method to get the 32-bit
    ' ARGB value of someColor (created from a KnownColor). Create
    ' a Color structure from the 32-bit ARGB value and set someColor
    ' equal to this new Color structure. Then use the ToString method
    ' to convert it to a string.
    g.DrawString(someColor.ToString(), myFont, Brushes.Black, _
    x + 55, y)
    someColor = Color.FromArgb(someColor.ToArgb())
    g.DrawString(someColor.ToString(), myFont, Brushes.Black, _
    x + 55, y + 15)
    y += 40
    Next i
    End Sub

  • private Sub GetColorComponent(Color pixelColor, int colorComponent

    Select Case ColorComponent
    case 0
    returnValue = pixelColor.R
    case 1
    returnValue = pixelColor.G
    case 2
    returnValue = pixelColor.B
    End Select

    end sub
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories