-
July 25th, 2005, 03:31 PM
#1
converting byte data to Drawing.Color
I'm writing a simple app to open Grand Prix Legends' funky PBF files used to store screenshot bitmaps in 16-bit rgb 565 format where each pixel's color is represented by two bytes.
SetPixel requires a Color parameter. How do I convert those two bytes to System.Drawing.Color type?
Thanks,
Homer
-
July 25th, 2005, 09:33 PM
#2
Re: converting byte data to Drawing.Color
Check the Color.FromArgb method.
-
July 27th, 2005, 02:15 PM
#3
Re: converting byte data to Drawing.Color
ToARGB/FromARGB will not accept a two byte color value. RGB 565 uses 5 bits for red, 6 bits for green, and 5 bits for blue. ARGB uses one byte each for alpha, red, green, and blue.
I am having limited success using the color translator:
Code:
pixColor = ColorTranslator.FromWin32(buffer(i + 1) * &H100 Or buffer(i))
imgbmp.SetPixel(x, y, pixColor)
Unfortunately the resulting image looks like it came from a monochrome monitor.
Is there a similar method like ToARGB that accepts a two-byte color value that I don't know about?
-
July 28th, 2005, 08:08 AM
#4
Re: converting byte data to Drawing.Color
Maybe you want something like this.. I didn't test it.
EXAMPLE :
Code:
Dim b As Integer
b = 65535
Const RED As Integer = 63488
Const green As Integer = 2016
Const blue As Integer = 31
Const MaxRed As Integer = 31
Const MaxGreen As Integer = 63
Const MaxBlue As Integer = 31
Dim bred As Integer = (b And RED)
Dim bgreen As Integer = (b And green)
Dim bblue As Integer = (b And blue)
bred = bred >> 11 ' ------ > Takes out the 0
bgreen = bgreen >> 5 ' ----- > takes out the 0
Dim flBred As Decimal = (bred \ MaxRed) 'Now you got the red proportion in byte
Dim flbgreen As Decimal = (bgreen \ MaxGreen)
Dim flbblue As Decimal = (bblue \ MaxBlue)
bred = CInt(flBred * 255)
bgreen = CInt(flbgreen * 255)
bblue = CInt(flbblue * 255)
Dim newColor As System.Drawing.Color
newColor = New System.Drawing.Color
newColor.FromArgb(bred, bgreen, bblue)
Nicolas Bohemier
-
July 29th, 2005, 03:02 PM
#5
Re: converting byte data to Drawing.Color
Thanks, Nicolas. I was stumped on how to separate the individual bits.
But VB.net won't let me use the C++ extraction operator (>>). Is there a VB equivalent?
-
July 31st, 2005, 12:49 PM
#6
Re: converting byte data to Drawing.Color
the >> operator in vb.net is the SHIFT operator
>> = shift right
<< = shift left
I'm doing the >> shift thing.. I don't see why you need to extract something..
If you mean read the data from a file or something then you need to check with stream classes I think.
But I thought you had your bits in memory
Nicolas Bohemier
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|