Announcement

Collapse
No announcement yet.

Converting RGB long back to three seperate numbers

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Converting RGB long back to three seperate numbers

    This is probaly an easy question. YOu know when oyu use the RGB function to convert 3 numbers into an RGB long? Well I want to do the opisite. I want to convert an RGB long back to the 3, 0 - 255 values.

    Code:
    rgb& = RGB(126, 25, 38)
    rgb& is now equal to: 2496894

    How do I convert rgb& back to 126, 25 and 38?

    ------------------
    Thank you,
    Ryan M. Cross
    Webmaster FlexiFish Inc. UK
    Likuid Creations Inc.
    Thank you,
    Ryan M. Cross

  • #2
    Ryan:
    Code:
       Temp&  = RGB(126, 25, 38)  ' 2496894
    
    
       Red&   = Temp& MOD 256
       Green& = (Temp& \ 256) MOD 256
       Blue&  = ((Temp& \ 256) \ 256) MOD 256
    Timm
    mailto:[email protected]
    Tsunami Record Manager

    Comment


    • #3
      I prefer Redim At
      Code:
         #Compile Exe
         Function PbMain
            Dim cRgb As Long
            ReDim cbRgb(3) As Byte At VarPtr(cRgb)
            cRgb = Rgb(126, 25, 38)
            MsgBox "R =" + Str$(cbRgb(0)) + " G =" + Str$(cbRgb(1)) + " B =" + Str$(cbRgb(2))
         End Function
      ------------------
      E-MAIL: [email protected]

      Comment


      • #4
        Here ya go...

        Code:
        #compile exe
        #register none
         
        sub ExtractRGB(byval rgbColor as long,Red as byte,Green as byte,Blue as byte)
            !mov eax,rgbColor
            !mov ebx,Red
            !mov [ebx],al
            !shr eax,8
            !mov ebx,Green
            !mov [ebx],al
            !shr eax,8
            !mov ebx,Blue
            !mov [ebx],al
        end sub
         
         
         
        function pbmain as long
            dim rgbColor as long
            dim Red as byte
            dim Green as byte
            dim Blue as byte
            
            'Red = 10
            'Green = 20
            'Blue = 30
            
            rgbColor = rgb(10,20,30)
            
            ExtractRGB rgbColor,Red,Green,Blue
            
            msgbox format$(Red,"Red = # ") & $CRLF & format$(Green,"Green = # ") & $CRLF & format$(Blue,"Blue = #")
        end function

        Hope this helps!


        ------------------
        Cheers!

        Comment

        Working...
        X