0

I have a function which returns average RGB value of a region drawn on a picturebox in VB.net.

The code is as below:

Function GetAvgRGB(ByVal CrdY As Integer, ByVal CrdX As Integer, ByVal Region As System.Drawing.Rectangle) As Tuple(Of Integer, Integer, Integer)

    Dim totalR As UInteger
    Dim totalG As UInteger
    Dim totalB As UInteger

    For y As Integer = CrdY - (Region.Height / 2) To CrdY + ((Region.Height / 2) - 1)
        For x As Integer = CrdX - (Region.Width / 2) To CrdX + ((Region.Width / 2) - 1)
            totalR += myBitmap.GetPixel(x, y).R
            totalG += myBitmap.GetPixel(x, y).G
            totalB += myBitmap.GetPixel(x, y).B
        Next
    Next

    Dim pixelCount As Integer = Region.Width * Region.Height

    Dim averageR As Integer = CType(totalR \ pixelCount, Integer)
    Dim averageG As Integer = CType(totalG \ pixelCount, Integer)
    Dim averageB As Integer = CType(totalB \ pixelCount, Integer)

    Return Tuple.Create(averageR, averageG, averageB)

End Function

My query is how do I separate the values of R, G & B returned by this function..

1
  • you mean by using Tuple.Item1, Tuple.Item2 and Tuple.Item3? Commented Feb 8, 2017 at 6:01

1 Answer 1

1

Use the Item property.

Dim myTuple = GetAvgRGB(?,?,?)
Dim r = myTuple.Item1 ' g = .Item2, b = .Item3
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for a quick resolution !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.