-
Jan 29th, 2010, 08:25 AM
#1
Thread Starter
Lively Member
BGR bytes to picture box?
I have a rom file that I want to display data from
The strings I have already retrieved and displayed the problem now is the image.
I have read all the bytes for the part of the file that contains all the data I
require EN_Title_Icon which is 2112 bytes.
The image data is offset 32 byes in EN_Title_Icon and is 512 bytes, How do I loop the bytes and put them as pixels in the picturebox or a bitmap?
And can i use the pallet data that is the 32 bytes after the image data?
Here is some info on the image
this is big endian, basically this means you need to flip the palette: ff7f becomes 7fff etc. Discard the first byte as it is seethrough as well.
Read the remaining 15 bytes and place them in the order they come out.
Read 16 bytes of the bitmap and call it a tile, repeat in rows of 4 tiles until all 512 bytes are used.
4bpp is 4 bits per pixel so every byte is 2 pixels and each tile has 32.
so these bytes merely define what colours are used, this is where it gets a bit tricky though as the nibbles will need flipping, Either way each nibble points to the colour at that place in the palette
code Code:
'lets see if we can reconstitute the icon BGR 512 bytes
Dim EN_Title_Icon As Integer = getOffset(rom)
Dim fileOpen As IO.FileStream = IO.File.Open(rom, IO.FileMode.Open, FileAccess.Read)
Dim b_Icon(2111) As Byte 'the data from the offset here
'reset the pointer
fileOpen.Position = 0
fileOpen.Seek(EN_Title_Icon, IO.SeekOrigin.Begin)
fileOpen.Read(b_Icon, 0, 2112) 'fill b_icon with bytes
'tile data is at offset 32 in b_Icon and is 512 bytes
fileOpen.Close()
Dim im(511) As Byte 'just the tile data
Buffer.BlockCopy(b_Icon, 32, im, 0, 512)
Dim bmp As Bitmap = New Bitmap(32, 32, Imaging.PixelFormat.Undefined)
PictureBox1.Image = bmp
Last edited by polecat; Jan 29th, 2010 at 09:00 AM.
Reason: added the buffer.blockcopy
-
Jan 29th, 2010, 09:10 AM
#2
Re: BGR bytes to picture box?
vb.net Code:
Dim bmp As Bitmap = New Bitmap(32, 32, Imaging.PixelFormat.Undefined) Dim x, y As Integer Dim c As System.Color x = 10 ' Demo y = 10 c = bmp.GetPixel(x, y) ' Read pixel color bmp.SetPixel( x, y, c) ' Set pixel color PictureBox1.Image = bmp
-
Jan 29th, 2010, 10:01 AM
#3
Thread Starter
Lively Member
Re: BGR bytes to picture box?
ok that gives me the idea of assigning the pixels in the bitmap but look
code Code:
Dim im(511) As Byte 'tile data
Dim pallet(31) As Byte 'pallet data
Buffer.BlockCopy(b_Icon, 32, im, 0, 512) ' tile data
Buffer.BlockCopy(b_Icon, 544, pallet, 0, 32) 'pallet data
TextBox2.Text = Nothing
For Each b In im
TextBox2.Text &= b & Environment.NewLine
Next
and this is expample output first 14 bytes
Code:
238
238
238
238
46
34
0
0
46
34
0
0
46
34
how can these represent a colour ? especialy if 1 byte is 2 pixels?
Tags for this Thread
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
|