Android Question count pixels that are red in bitmap ?

sorex

Expert
Licensed User
there is a bitmap getpixel command that you can use.

just check on FFFF0000 to get full red values.
 

Devv

Active Member
Licensed User
B4X:
    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 ?
 

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 ?
 

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.
 

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?
 

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
B4X:
'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....
B4X:
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.
 

sorex

Expert
Licensed User
@RandomCoder
ok bro, how could i know this number color -6710887 ? red , blue , white , yello ?
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.
 
Top