highboy Posted January 28, 2009 Posted January 28, 2009 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 Quote
Administrators PlausiblyDamp Posted January 28, 2009 Administrators Posted January 28, 2009 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
highboy Posted January 29, 2009 Author Posted January 29, 2009 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. ;) Quote
Administrators PlausiblyDamp Posted January 29, 2009 Administrators Posted January 29, 2009 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
highboy Posted January 29, 2009 Author Posted January 29, 2009 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. Quote
Administrators PlausiblyDamp Posted January 29, 2009 Administrators Posted January 29, 2009 What is the file used by? Does it have any documentation that explains it's file format? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
highboy Posted January 29, 2009 Author Posted January 29, 2009 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. Quote
Administrators PlausiblyDamp Posted January 29, 2009 Administrators Posted January 29, 2009 So if I use the colour Red (&HFFFF0000) what would you expect the file to contain (0000803F or the full 0000803F0000000000000000) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
highboy Posted January 29, 2009 Author Posted January 29, 2009 (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 January 29, 2009 by highboy Quote
highboy Posted February 2, 2009 Author Posted February 2, 2009 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 ;) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.