## 6 replies

Last post Jan 30, 2009 09:01 PM by neilhanvey

• neilhanvey

Member

88 Points

112 Posts

### color information

ok, here's what i wanna do

loop through a folder of images and compare the dominant color in each image against a range of hex codes so if a jpeg has 50 blue pixels, 25 black pixels and 25 red pixels i know it's predominantly blue

is something like this possible, anyone know where i should start?

color gdi+

• allanhorwitz

Participant

1456 Points

617 Posts

### Re: color information

I would begin by searching through the System.Drawing namespace at:

http://msdn.microsoft.com/en-us/library/system.drawing.graphics.aspx

Also, take a look at:

http://www.bobpowell.net/lockingbits.htm

Allan Horwitz
• neilhanvey

Member

88 Points

112 Posts

### Re: color information

ok, after much digging and reading (i'm admittely not very good at this programming thing, data access i'm fine at but stuff like this...urgh) i've found the following function but can anybody help me convert it into something that would run on a web page as picturebox is a windows forms control....please somebody help as this is driving me crazy

Function AverageRGB(ByRef P As PictureBox) As Long

Dim Count As Long
Dim Red As Long
Dim Green As Long
Dim Blue As Long
Dim Hexed As String
Dim X As Long
Dim Y As Long
Count = 0

For X = 0 To P.Width Step P.Width \ 32

For Y = 0 To P.Height Step P.Height \ 32
Hexed = Right("00000" & Hex(P.Point(X, Y)), 6)
Red = Red + CLng("&h" & Right(Hexed, 2))
Green = Green + CLng("&h" & Mid(Hexed, 3, 2))
Blue = Blue + CLng("&h" & Left(Hexed, 2))
Count = Count + 1
Next

Next

AverageRGB = RGB(Red \ Count, Green \ Count, Blue \ Count)

End Function

color gdi+ common color average color dominant color

• allanhorwitz

Participant

1456 Points

617 Posts

### Re: color information

Have you looked into System.Drawing.Image?

Allan Horwitz
• neilhanvey

Member

88 Points

112 Posts

### Re: color information

i figured it all out in the end using lockbits. if anyone ever needs the code, give me a shout at neil_akoga@hotmail.com

• allanhorwitz

Participant

1456 Points

617 Posts

### Re: color information

Would you mind posting some snippets here?

Allan Horwitz
• neilhanvey

Member

88 Points

112 Posts