Results 1 to 3 of 3

Thread: BGR bytes to picture box?

  1. #1

    Thread Starter
    Lively Member polecat's Avatar
    Join Date
    Jul 2005
    Location
    Wolverhampton
    Posts
    83

    Question 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:
    1. 'lets see if we can reconstitute the icon BGR 512 bytes
    2.  
    3.         Dim EN_Title_Icon As Integer = getOffset(rom)
    4.         Dim fileOpen As IO.FileStream = IO.File.Open(rom, IO.FileMode.Open, FileAccess.Read)
    5.         Dim b_Icon(2111) As Byte 'the data from the offset here
    6.         'reset the pointer
    7.         fileOpen.Position = 0
    8.         fileOpen.Seek(EN_Title_Icon, IO.SeekOrigin.Begin)
    9.         fileOpen.Read(b_Icon, 0, 2112) 'fill b_icon with bytes
    10.  
    11.         'tile data is at offset 32 in b_Icon and is 512 bytes
    12.  
    13.         fileOpen.Close()
    14.  
    15.         Dim im(511) As Byte 'just the tile data
    16.  
    17.         Buffer.BlockCopy(b_Icon, 32, im, 0, 512)
    18.  
    19.         Dim bmp As Bitmap = New Bitmap(32, 32, Imaging.PixelFormat.Undefined)
    20.         PictureBox1.Image = bmp
    Last edited by polecat; Jan 29th, 2010 at 09:00 AM. Reason: added the buffer.blockcopy

  2. #2
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: BGR bytes to picture box?

    vb.net Code:
    1. Dim bmp As Bitmap = New Bitmap(32, 32, Imaging.PixelFormat.Undefined)
    2. Dim x, y As Integer
    3. Dim c As System.Color
    4.  
    5. x = 10  ' Demo
    6. y = 10
    7.  
    8. c = bmp.GetPixel(x, y) ' Read pixel color
    9.  
    10. bmp.SetPixel( x, y, c) ' Set pixel color
    11.  
    12.  PictureBox1.Image = bmp

  3. #3

    Thread Starter
    Lively Member polecat's Avatar
    Join Date
    Jul 2005
    Location
    Wolverhampton
    Posts
    83

    Re: BGR bytes to picture box?

    ok that gives me the idea of assigning the pixels in the bitmap but look

    code Code:
    1. Dim im(511) As Byte 'tile data
    2.         Dim pallet(31) As Byte 'pallet data
    3.  
    4.         Buffer.BlockCopy(b_Icon, 32, im, 0, 512) ' tile data
    5.         Buffer.BlockCopy(b_Icon, 544, pallet, 0, 32) 'pallet data
    6.  
    7.         TextBox2.Text = Nothing
    8.  
    9.         For Each b In im
    10.  
    11.             TextBox2.Text &= b & Environment.NewLine
    12.  
    13.         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
  •  



Click Here to Expand Forum to Full Width