Fastest way to get pixel colour value?

Discussion in 'Questions (Windows Mobile)' started by DavidN, Aug 22, 2007.

  1. DavidN

    DavidN Member Licensed User

    I want to selectively get the Red, Green, or Blue value for a pixel. Ideally, I would like 3 functions: GetPixelRed(), GetPixelGreen(), and GetPixelBlue(). Each function would return a value from 0..255. This would better complement the existing SetPixel() function which takes 3 integers as arguments.

    The existing GetPixel() function just returns a 32-bit value that I assume/suspect consists of the following byte fields
    Byte 3 = 0xFF
    Byte 2 = Red Value (0..255)
    Byte 1 = Green Value (0..255)
    Byte 0 = Blue Value (0..255)

    I could extract the particular R, G, or B value from this 32-bit value using some bitwise manipulation, but am concerned that the compiler wouldn't optimize it fast enough for my needs.

    Any ideas of what the fastest way to get a Red, Green, or Blue colour value from a pixel would be?

  2. Cableguy

    Cableguy Expert Licensed User

    Try the following

    ad three varables to the globals:
    R,G,B -This will be the color components

    The in the whatever sub
    try :

    msgbox("Your color is mador Red("&R&"), Green("&G&"), and Blue("&B&")")

    Please note that this is un-tested code...but i Think it will do what you want...
  3. specci48

    specci48 Well-Known Member Licensed User

    I don't know if this is the fastet way but it works:

    Sub Globals
       red = 
       green = 
       blue = 
    End Sub

    Sub App_Start
    End Sub

    Sub Color2RGB(color)
       colorNum = color + 
       red = Int(colorNum / 
       green = Int((colorNum - red * 
    65536) / 256)   
       blue = colorNum - red * 
    65536 - green * 256
    End Sub

  4. Erel

    Erel Administrator Staff Member Licensed User

    specci48 method is the right way to do it.
    Next version will include a GetRGB method that will return the three components of a color.
  5. hung

    hung Member Licensed User

    I got something similar in one of my program.

    vC = form1.GetPixel(x, y) + 16777216
    vR = Int(vC / 65536)
    vG = Int((vC Mod 65536) / 256)
    vB = vC Mod 256

    But that assumes the PPC is using 65535 colors, other color pallet will not work.
  6. DavidN

    DavidN Member Licensed User

    That's great! Hopefully it'll run faster than the work arounds. When do you think this next release will be?
    1. days?
    2. weeks?
    3. months?
    4. All of the above?
    5. None of the above?

    Thanks for your work at improving an impressive product.
  7. Erel

    Erel Administrator Staff Member Licensed User

    I guess it will be option number 3.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice