Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

how many bytes in a bitmap pixel?

Hi
I am trying to fill an array with a bitmap file. How many bytes are there in each pixel or pel of the bitmap image? I have been writing in 2 bytes per pixel but this is wrong i think.

regards
kev

Comments

  • Josh CodeJosh Code Member Posts: 675
    [b][red]This message was edited by Josh Code at 2002-10-7 20:14:46[/red][/b][hr]
    : Hi
    : I am trying to fill an array with a bitmap file. How many bytes are there in each pixel or pel of the bitmap image? I have been writing in 2 bytes per pixel but this is wrong i think.
    :
    : regards
    : kev
    :

    There are many types of bitmaps.
    There are also different pixel formats for them. Some use palettes and some don't.
    Make sure that you load it as a binary file. I made that mistake.

    In windows bitmaps, any palette entries use 4 bytes.
    There is a short(16-bit integer) starting at the 29th byte in the file that determines the pixel format(bits per pixel).

    Look at a few *.bmp files in a hex editor to see how information is stored in them.

    The width is a 4 byte integer starting at the 19th byte of the file.
    The height is a 4 byte integer starting at the 23rd byte.

    Here are some explanations of a few pixel formats.
    1: monochrome, 8 pixels stored in 1 byte, uses 2 palette entries.
    4: 16 colour, 2 pixels stored in 1 byte, uses 16 palette entries.
    8: 256 colour, 1 pixel in 1 byte, uses a 256 colour palette
    16: 2 bytes per pixel, uses r,g,b values(5 bits each)
    24: 3 bytes per pixel, uses r,g,b values(8 bits each)
    32: 4 bytes per pixel, uses an alpha byte(basically unused) and r,g,b values(8 bits each)

    If the bits per pixel is less than or equal to 8(using a palette), the palette entries start at the 55th byte of the bitmap.

    The pixel data starts right after the palette entries. If the palette isn't used, the pixel data starts at the 55th byte.


  • kevanwoodcockkevanwoodcock Member Posts: 172
    : : Hi
    : : I am trying to fill an array with a bitmap file. How many bytes are there in each pixel or pel of the bitmap image? I have been writing in 2 bytes per pixel but this is wrong i think.
    : :
    : : regards
    : : kev
    : :
    :
    : There are many types of bitmaps.
    : There are also different pixel formats for them. Some use palettes and some don't.
    : Make sure that you load it as a binary file. I made that mistake.
    :
    : In windows bitmaps, any palette entries use 4 bytes.
    : There is a short(16-bit integer) starting at the 29th byte in the file that determines the pixel format(bits per pixel).
    :
    : Look at a few *.bmp files in a text editor to see how information is stored in them.
    :
    : The width is a 4 byte integer starting at the 19th byte of the file.
    : The height is a 4 byte integer starting at the 23rd byte.
    :
    : Here are some explanations of a few pixel formats.
    : 1: monochrome, 8 pixels stored in 1 byte, uses 2 palette entries.
    : 4: 16 colour, 2 pixels stored in 1 byte, uses 16 palette entries.
    : 8: 256 colour, 1 pixel in 1 byte, uses a 256 colour palette
    : 16: 2 bytes per pixel, uses r,g,b values(5 bits each)
    : 24: 3 bytes per pixel, uses r,g,b values(8 bits each)
    : 32: 4 bytes per pixel, uses an alpha byte(basically unused) and r,g,b values(8 bits each)
    :
    : If the bits per pixel is less than or equal to 8(using a palette), the palette entries start at the 55th byte of the bitmap.
    :
    : The pixel data starts right after the palette entries. If the palette isn't used, the pixel data starts at the 55th byte.
    :

    Thanks, that great info. I have looked at some bmp files in note pad and word pad but they just look like garbage to me. I cannot see any clear 29th byte for the pixel format. How do i determine this? Well actually i am just saving bmp files in 256 colour in Paint. So I assume that now i know that each pixel is equal to one byte.???? is this so?
    If so then i just count the first 55 bytes out and then I am into the pixel data? is this correct?

    thanks again for your help.

    kev

  • Josh CodeJosh Code Member Posts: 675
    : : : Hi
    : : : I am trying to fill an array with a bitmap file. How many bytes are there in each pixel or pel of the bitmap image? I have been writing in 2 bytes per pixel but this is wrong i think.
    : : :
    : : : regards
    : : : kev
    : : :
    : :
    : : There are many types of bitmaps.
    : : There are also different pixel formats for them. Some use palettes and some don't.
    : : Make sure that you load it as a binary file. I made that mistake.
    : :
    : : In windows bitmaps, any palette entries use 4 bytes.
    : : There is a short(16-bit integer) starting at the 29th byte in the file that determines the pixel format(bits per pixel).
    : :
    : : Look at a few *.bmp files in a text editor to see how information is stored in them.
    : :
    : : The width is a 4 byte integer starting at the 19th byte of the file.
    : : The height is a 4 byte integer starting at the 23rd byte.
    : :
    : : Here are some explanations of a few pixel formats.
    : : 1: monochrome, 8 pixels stored in 1 byte, uses 2 palette entries.
    : : 4: 16 colour, 2 pixels stored in 1 byte, uses 16 palette entries.
    : : 8: 256 colour, 1 pixel in 1 byte, uses a 256 colour palette
    : : 16: 2 bytes per pixel, uses r,g,b values(5 bits each)
    : : 24: 3 bytes per pixel, uses r,g,b values(8 bits each)
    : : 32: 4 bytes per pixel, uses an alpha byte(basically unused) and r,g,b values(8 bits each)
    : :
    : : If the bits per pixel is less than or equal to 8(using a palette), the palette entries start at the 55th byte of the bitmap.
    : :
    : : The pixel data starts right after the palette entries. If the palette isn't used, the pixel data starts at the 55th byte.
    : :
    :
    : Thanks, that great info. I have looked at some bmp files in note pad and word pad but they just look like garbage to me. I cannot see any clear 29th byte for the pixel format. How do i determine this? Well actually i am just saving bmp files in 256 colour in Paint. So I assume that now i know that each pixel is equal to one byte.???? is this so?
    : If so then i just count the first 55 bytes out and then I am into the pixel data? is this correct?
    :
    : thanks again for your help.
    :
    : kev
    :

    I said text editor but I meant hex editor. A hex editor can always help you figure out a binary file format.

    The pixel data should start at byte number (55+4*256) or 1079.
    This is because the palette entires would be stored before the pixel data.

    I have tried loading a bitmap file as you are and run into some problems with getting the pixel data. What I was really after was the palette entries. My problem with loading the bitmaps was that sometimes they looked sheared. I mean something like a vertical line in the bitmap would look diagonal when I drawed what I loaded.


    An easier way of moving the pixel data into an array would be to load the bitmap file into a bitmap variable. After that, copy the information out of scanlines into the array. Scanlines would be efficient. If you want something easier, loop through all the pixels in the bitmap and use GetPixel.

    Here are some links that might help you out.

    Explains and shows you some c code to help
    http://www.dcs.ed.ac.uk/home/mxr/gfx/2d/BMP.txt

    You can download some docs on the bitmap format here:
    http://www.wotsit.org/search.asp?s=graphics

    Explains and shows you some Visual Basic code to help
    http://rookscape.com/vbgaming/tutR.php

    http://www.prepressure.com/formats/bmp/fileformat.htm
  • kevanwoodcockkevanwoodcock Member Posts: 172
    : : : : Hi
    : : : : I am trying to fill an array with a bitmap file. How many bytes are there in each pixel or pel of the bitmap image? I have been writing in 2 bytes per pixel but this is wrong i think.
    : : : :
    : : : : regards
    : : : : kev
    : : : :
    : : :
    : : : There are many types of bitmaps.
    : : : There are also different pixel formats for them. Some use palettes and some don't.
    : : : Make sure that you load it as a binary file. I made that mistake.
    : : :
    : : : In windows bitmaps, any palette entries use 4 bytes.
    : : : There is a short(16-bit integer) starting at the 29th byte in the file that determines the pixel format(bits per pixel).
    : : :
    : : : Look at a few *.bmp files in a text editor to see how information is stored in them.
    : : :
    : : : The width is a 4 byte integer starting at the 19th byte of the file.
    : : : The height is a 4 byte integer starting at the 23rd byte.
    : : :
    : : : Here are some explanations of a few pixel formats.
    : : : 1: monochrome, 8 pixels stored in 1 byte, uses 2 palette entries.
    : : : 4: 16 colour, 2 pixels stored in 1 byte, uses 16 palette entries.
    : : : 8: 256 colour, 1 pixel in 1 byte, uses a 256 colour palette
    : : : 16: 2 bytes per pixel, uses r,g,b values(5 bits each)
    : : : 24: 3 bytes per pixel, uses r,g,b values(8 bits each)
    : : : 32: 4 bytes per pixel, uses an alpha byte(basically unused) and r,g,b values(8 bits each)
    : : :
    : : : If the bits per pixel is less than or equal to 8(using a palette), the palette entries start at the 55th byte of the bitmap.
    : : :
    : : : The pixel data starts right after the palette entries. If the palette isn't used, the pixel data starts at the 55th byte.
    : : :
    : :
    : : Thanks, that great info. I have looked at some bmp files in note pad and word pad but they just look like garbage to me. I cannot see any clear 29th byte for the pixel format. How do i determine this? Well actually i am just saving bmp files in 256 colour in Paint. So I assume that now i know that each pixel is equal to one byte.???? is this so?
    : : If so then i just count the first 55 bytes out and then I am into the pixel data? is this correct?
    : :
    : : thanks again for your help.
    : :
    : : kev
    : :
    :
    : I said text editor but I meant hex editor. A hex editor can always help you figure out a binary file format.
    :
    : The pixel data should start at byte number (55+4*256) or 1079.
    : This is because the palette entires would be stored before the pixel data.
    :
    : I have tried loading a bitmap file as you are and run into some problems with getting the pixel data. What I was really after was the palette entries. My problem with loading the bitmaps was that sometimes they looked sheared. I mean something like a vertical line in the bitmap would look diagonal when I drawed what I loaded.
    :
    :
    : An easier way of moving the pixel data into an array would be to load the bitmap file into a bitmap variable. After that, copy the information out of scanlines into the array. Scanlines would be efficient. If you want something easier, loop through all the pixels in the bitmap and use GetPixel.
    :
    : Here are some links that might help you out.
    :
    : Explains and shows you some c code to help
    : http://www.dcs.ed.ac.uk/home/mxr/gfx/2d/BMP.txt
    :
    : You can download some docs on the bitmap format here:
    : http://www.wotsit.org/search.asp?s=graphics
    :
    : Explains and shows you some Visual Basic code to help
    : http://rookscape.com/vbgaming/tutR.php
    :
    : http://www.prepressure.com/formats/bmp/fileformat.htm
    :

  • kevanwoodcockkevanwoodcock Member Posts: 172
    : : : : Hi
    : : : : I am trying to fill an array with a bitmap file. How many bytes are there in each pixel or pel of the bitmap image? I have been writing in 2 bytes per pixel but this is wrong i think.
    : : : :
    : : : : regards
    : : : : kev
    : : : :
    : : :
    : : : There are many types of bitmaps.
    : : : There are also different pixel formats for them. Some use palettes and some don't.
    : : : Make sure that you load it as a binary file. I made that mistake.
    : : :
    : : : In windows bitmaps, any palette entries use 4 bytes.
    : : : There is a short(16-bit integer) starting at the 29th byte in the file that determines the pixel format(bits per pixel).
    : : :
    : : : Look at a few *.bmp files in a text editor to see how information is stored in them.
    : : :
    : : : The width is a 4 byte integer starting at the 19th byte of the file.
    : : : The height is a 4 byte integer starting at the 23rd byte.
    : : :
    : : : Here are some explanations of a few pixel formats.
    : : : 1: monochrome, 8 pixels stored in 1 byte, uses 2 palette entries.
    : : : 4: 16 colour, 2 pixels stored in 1 byte, uses 16 palette entries.
    : : : 8: 256 colour, 1 pixel in 1 byte, uses a 256 colour palette
    : : : 16: 2 bytes per pixel, uses r,g,b values(5 bits each)
    : : : 24: 3 bytes per pixel, uses r,g,b values(8 bits each)
    : : : 32: 4 bytes per pixel, uses an alpha byte(basically unused) and r,g,b values(8 bits each)
    : : :
    : : : If the bits per pixel is less than or equal to 8(using a palette), the palette entries start at the 55th byte of the bitmap.
    : : :
    : : : The pixel data starts right after the palette entries. If the palette isn't used, the pixel data starts at the 55th byte.
    : : :
    : :
    : : Thanks, that great info. I have looked at some bmp files in note pad and word pad but they just look like garbage to me. I cannot see any clear 29th byte for the pixel format. How do i determine this? Well actually i am just saving bmp files in 256 colour in Paint. So I assume that now i know that each pixel is equal to one byte.???? is this so?
    : : If so then i just count the first 55 bytes out and then I am into the pixel data? is this correct?
    : :
    : : thanks again for your help.
    : :
    : : kev
    : :
    :
    : I said text editor but I meant hex editor. A hex editor can always help you figure out a binary file format.
    :
    : The pixel data should start at byte number (55+4*256) or 1079.
    : This is because the palette entires would be stored before the pixel data.
    :
    : I have tried loading a bitmap file as you are and run into some problems with getting the pixel data. What I was really after was the palette entries. My problem with loading the bitmaps was that sometimes they looked sheared. I mean something like a vertical line in the bitmap would look diagonal when I drawed what I loaded.
    :
    :
    : An easier way of moving the pixel data into an array would be to load the bitmap file into a bitmap variable. After that, copy the information out of scanlines into the array. Scanlines would be efficient. If you want something easier, loop through all the pixels in the bitmap and use GetPixel.
    :
    : Here are some links that might help you out.
    :
    : Explains and shows you some c code to help
    : http://www.dcs.ed.ac.uk/home/mxr/gfx/2d/BMP.txt
    :
    : You can download some docs on the bitmap format here:
    : http://www.wotsit.org/search.asp?s=graphics
    :
    : Explains and shows you some Visual Basic code to help
    : http://rookscape.com/vbgaming/tutR.php
    :
    : http://www.prepressure.com/formats/bmp/fileformat.htm
    :

  • Justin BibJustin Bib USAMember Posts: 0

    ( http://forcoder.org ) free ebooks and video tutorials about ( Perl Scratch Swift Python Java PL/SQL C# Go Assembly Ruby Visual Basic .NET Objective-C Delphi PHP Visual Basic R MATLAB C JavaScript C++ ABAP D Apex Julia FoxPro Clojure Erlang Bash Ada F# Kotlin Alice Scala Prolog LabVIEW Rust Fortran Awk Lisp SAS Transact-SQL VBScript Dart Hack COBOL Scheme Lua ML Crystal Logo ) ________

Sign In or Register to comment.