Android Question count pixels that are red in bitmap ?

Discussion in 'Android Questions' started by Devv, Apr 7, 2015.

  1. Devv

    Devv Active Member Licensed User

    how could i count pixels that are red in a bitmap ?
     
  2. sorex

    sorex Expert Licensed User

    there is a bitmap getpixel command that you can use.

    just check on FFFF0000 to get full red values.
     
    Devv likes this.
  3. Devv

    Devv Active Member Licensed User

    Code:
    Dim test As Bitmap
        test.Initialize(
    File.DirRootExternal,"test.png")
       
        
    Msgbox(test.GetPixel(300,10),"")
    i'am always getting -8 numbers !!
    ex: -6710887

    what is these numbers ?
     
  4. Peter Simpson

    Peter Simpson Expert Licensed User

    Those numbers is the color of the pixel located at 300x and 10y on your bitmap image as an integer (ARGB)...
     
    giga, DonManfred and Devv like this.
  5. Devv

    Devv Active Member Licensed User

    what does the "-" stand for ?
    how could i translate it to human color or hex ?
    another question is : will the image height be the same as the last y pixel and image width the last x pixel ?
     
  6. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Any signed integer with a 1 set in the most significant bit position will cause the number to be negative. Don't worry about it, that's just how it works. Why do you want to convert to hex? You can just use the integer representation instead.
    Yes the last x and y position will be found by the width and height of the image.
     
    Peter Simpson likes this.
  7. RandomCoder

    RandomCoder Well-Known Member Licensed User

    PS. You might want to check for a range of reds rather than just FFFF0000h as this is only the value for pure red that is fully opaque. It depends what you want to achieve?
     
    Devv likes this.
  8. Devv

    Devv Active Member Licensed User

    @RandomCoder
    ok bro, how could i know this number color -6710887 ? red , blue , white , yello ?
     
  9. RandomCoder

    RandomCoder Well-Known Member Licensed User

    I've not got my PC to hand, only my tablet but think that you should be able to check for a range of integer values between your chosen shades of red. However if you want to get each ARGB value from the integer you can use Erel's sample code detailed here...How to convert Int to R,G,B,Trans?
     
    Peter Simpson likes this.
  10. RandomCoder

    RandomCoder Well-Known Member Licensed User

    I've just remembered that I once programmed an App that counted a time down, in doing so it changed the Activity background from green through to orange and finally red. It did this using the HSV colour model. Maybe the code will be of use to you as shades of red are any value were my variable 'percent' is approx 30% or less. This was found somewhere on Stack Overflow I think and so all credit goes to that person :D
    Code:
    'Code module
    'Subs in this code module will be accessible from all modules.
    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.
        Dim cR,cG,cB As Int
    End Sub

    Sub HSV2RGB(h As Float,s As Float,v As Float)
    Dim i As Int
    Dim r,g,b As Float
    Dim f,p,q,t As Float

        
    If s=0 Then
            
    'achromatic (grey)
            r=v
            g=v
            b=v
        
    Else   
            h=h/
    60
            i=
    Floor(h)
            f=h-i
            p=v*(
    1-s)
            q=v*(
    1-s*f)
            t=v*(
    1-s*(1-f))
            
    Select i
                
    Case 0:
                    r=v
                    g=t
                    b=p
                
    Case 1:
                    r=q
                    g=v
                    b=p
                
    Case 2:
                    r=p
                    g=v
                    b=t
                
    Case 3:
                    r=p
                    g=q
                    b=v
                
    Case 4:
                    r=t
                    g=p
                    b=v
                
    Case 5:
                    r=v
                    g=p
                    b=q
            
    End Select
        
    End If
            cR=
    Floor(255*r)
            cG=
    Floor(255*g)
            cB=
    Floor(255*b)
    End Sub
    Called using the following sub....
    Code:
    Sub SetColor(Percent As Float)
        
    'Change background from green to red as time runs low
        H=Percent*0.4*360    ' Hue (note 0.4 = Green)
        S=0.9                ' Saturation
        V=0.9                ' Value
        'Call function to convert HSB to RGB values
        HSV2RGB.HSV2RGB(H,S,V)
        
    'Modify activity background as time elapses
        Activity.Color=Colors.RGB(HSV2RGB.cR,HSV2RGB.cG,HSV2RGB.cB)
    End Sub
    Just a thought that using a different colour model might make it easier to extract different shades or a range of reds.
     
  11. sorex

    sorex Expert Licensed User

    you need to know their rgb value.

    red > FF0000
    blue > 00FF00
    white > FFFFFF
    yellow > FFFF00 ?

    but as said before these are the full colored ones. if you take a darker tint it has another value.

    you could calculate brightness and work with a brightness sorted color array.
     
Loading...
  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