binary to rgb

highboy

Newcomer
Joined
Nov 8, 2008
Messages
14
i am on a new project and am facing another problem.i dont know if i can but id like to get a color value from say 0000803F or from 00000000000000001000000000111111 both are the same thing one in hex and the other in binary but i just cant seem to make heads or tails of it.if thats out of the question maybe you can help me write the color value i have this so far

Code:
If dlgColor.ShowDialog() = DialogResult.OK Then

            PictureBox1.BackColor = dlgColor.Color()

            Dim str As String = (hex2bin(System.Drawing.ColorTranslator.ToWin32(dlgColor.Color)))

            Dim fs1 As New FileStream(Application.StartupPath & "/files/test1.bin", FileMode.OpenOrCreate, FileAccess.Write)
            Dim bwriter1 As New BinaryWriter(fs1)
            Dim i As Integer = str
            bwriter1.Write(i)
            bwriter1.Close()
            fs1.Close()
        End If

i would be very happy if i can get this to work.thanks you in advance
 
What is the code for the hex2bin method? Could you not just write it out as an integer and read it back as one?

Could you not just use something like
Visual Basic:
If dlgColor.ShowDialog() = DialogResult.OK Then

            PictureBox1.BackColor = dlgColor.Color()

            Dim fs1 As New FileStream(Application.StartupPath & "/files/test1.bin", FileMode.OpenOrCreate, FileAccess.Write)
            Dim bwriter1 As New BinaryWriter(fs1)
            Dim i As Integer = dlgColor.Color.ToArgb
            bwriter1.Write(i)
            bwriter1.Close()
            fs1.Close()

and once you have read the integer back just use
Visual Basic:
Dim c as Color = Color.FromArgb(<integer>)
to get it back.
 
thank you for replying but i just can seem to get anything to work. :confused:
the closest was to use single instead of Integer but anyway im lost.maybe i need a way to write the float values like this is what im looking at in hex editor.



the red float value is 1 and the green and blue are 0.the lenght of that string is 12 bytes so i need to read that and get red out of it somehow.i know im still learning but i just cant get this one.thank you again for your help and i sure hope you can help me somehow. ;)
 
Visual Basic:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If dlgColor.ShowDialog() = DialogResult.OK Then

            PictureBox1.BackColor = dlgColor.Color()

            Dim fs1 As New FileStream(Application.StartupPath & "/test1.bin", FileMode.OpenOrCreate, FileAccess.Write)
            Dim bwriter1 As New BinaryWriter(fs1)
            Dim i As Integer = dlgColor.Color.ToArgb
            bwriter1.Write(i)
            bwriter1.Close()
            fs1.Close()
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim fs1 As New FileStream(Application.StartupPath & "/test1.bin", FileMode.Open, FileAccess.Read)
        Dim breader1 As New BinaryReader(fs1)
        Dim i As Integer = breader1.ReadInt32()
        breader1.Close()
        fs1.Close()

        Dim c As Color = Color.FromArgb(i)
        PictureBox1.BackColor = c
    End Sub

worked fine for me.
 
Visual Basic:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If dlgColor.ShowDialog() = DialogResult.OK Then

            PictureBox1.BackColor = dlgColor.Color()

            Dim fs1 As New FileStream(Application.StartupPath & "/test1.bin", FileMode.OpenOrCreate, FileAccess.Write)
            Dim bwriter1 As New BinaryWriter(fs1)
            Dim i As Integer = dlgColor.Color.ToArgb
            bwriter1.Write(i)
            bwriter1.Close()
            fs1.Close()
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim fs1 As New FileStream(Application.StartupPath & "/test1.bin", FileMode.Open, FileAccess.Read)
        Dim breader1 As New BinaryReader(fs1)
        Dim i As Integer = breader1.ReadInt32()
        breader1.Close()
        fs1.Close()

        Dim c As Color = Color.FromArgb(i)
        PictureBox1.BackColor = c
    End Sub

worked fine for me.

ya i know but if you look at test1.bin in hex editor it doesn't match what i pointed out above in the picture.im sorry if i didn't make myself clear but that is why i am having such a hard time.red has to look like above.i have to write to an existing file not one i am making from scratch so it has to be in that same format.thank you so much for what you have given this far.
 
What is the file used by? Does it have any documentation that explains it's file format?

it is a module file and no unfortunately theres not much to go by.like i can write to it as i asked u before,that was for the header part of anouther file but same kind and i could take the length of the file and write it no problem.this color thing is a different story like i get how its going rgb 4 bytes for each one and with the float is set at 1 is full strength for that color.i just and lost in trying to get it done in code.all the information i got was in the hex editor looking at the file.again thanks so much man at least you are trying to give a guy a hand.
 
So if I use the colour Red (&HFFFF0000) what would you expect the file to contain (0000803F or the full 0000803F0000000000000000)

i need the full red = (red 0000 803F green 0000 0000 blue 0000 0000) and and each 4 digits are 2 bytes.so the red = 4 ,green = 4,blue = 4 as a total of 12 bytes.
to make yellow it would be like (red 0000 803F green 0000 803F blue 0000 0000)
i just remembered i did write to my test file similar to (&HFFFF0000) but it was reversed like 0000 FFFF not sure how atm for i have been trying some many things
 
Last edited:
i need the full red = (red 0000 803F green 0000 0000 blue 0000 0000) and and each 4 digits are 2 bytes.so the red = 4 ,green = 4,blue = 4 as a total of 12 bytes.
to make yellow it would be like (red 0000 803F green 0000 803F blue 0000 0000)
i just remembered i did write to my test file similar to (&HFFFF0000) but it was reversed like 0000 FFFF not sure how atm for i have been trying some many things

i am happy to say i solved this problem.thank you for all the help ;)
 
Back
Top