locked
color information RRS feed

  • Question

  • User2045693258 posted

    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?

    Friday, January 23, 2009 11:49 AM

Answers

All replies

  • User815882678 posted

    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

     

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 23, 2009 1:33 PM
  • User2045693258 posted

     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

    Tuesday, January 27, 2009 4:01 AM
  • User815882678 posted

    Have you looked into System.Drawing.Image?

    Tuesday, January 27, 2009 2:00 PM
  • User2045693258 posted

     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

    Friday, January 30, 2009 8:34 AM
  • User815882678 posted

    Would you mind posting some snippets here?

    Friday, January 30, 2009 10:11 AM
  • User2045693258 posted

    i'll post a link to the complete source here soon. i'm building a dynamic stock library project that gets color information and loads of other stuff including creating thumbnails on the fly etc . it should have a lot of useful gdi+ stuff in it as it's the one area of .net that i like the most :)

    Friday, January 30, 2009 9:01 PM