Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

 

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

  • Administrators
Posted

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

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

Dim c as Color = Color.FromArgb()

to get it back.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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.

 

http://img204.imageshack.us/img204/8248/sendon5.jpg

 

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. ;)

  • Administrators
Posted

   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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
   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.

Posted
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.

Posted (edited)
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

Edited by highboy
Posted
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 ;)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...