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?

    Thanks,
     
  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 :

    RGB(R,G,B)=getpixel(x,y)
    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:

    Code:
    Sub Globals
       red = 
    0
       green = 
    0
       blue = 
    0   
    End Sub

    Sub App_Start
       ...
       Color2RGB(bitmap1.GetPixel1(w,h))
       ...      
    End Sub

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

    specci48
     
  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.
     
Loading...