본문 바로가기

김탱 개발자/C/C++

raw파일과 bmp파일의 관계

출처 : 네이버 지식인

제가 알기론 bmp 파일raw 파일에 헤더만 붙어있습니다.

 

bmp 파일의 헤더 구조를 설명드리자면...

우선.. 기준이 되는 bmp파일 설정 :  256 Color의 색상을 갖는 bmp파일 분석

파일 구조.

BitMap File Header :(Size(Byte))

start size name stdvalue purpose
1 2 bfType 19778 must always be set to 'BM' to declare that this is a .bmp-file.
3 4 bfSize ?? specifies the size of the file in bytes.
7 2 bfReserved1 0 must always be set to zero.
9 2 bfReserved2 0 must always be set to zero.
11 4 bfOffBits 1078 specifies the offset from the beginning of the file to the bitmap data

Bitmap Infor Header :(Size(Byte))

start size name stdvalue purpose
15 4 biSize 40 specifies the size of the BITMAPINFOHEADER structure, in bytes.
19 4 biWidth 100 specifies the width of the image, in pixels.
23 4 biHeight 100 specifies the height of the image, in pixels.
27 2 biPlanes 1 specifies the number of planes of the target device, must be set to zero.
29 2 biBitCount 8 specifies the number of bits per pixel.
31 4 biCompression 0 Specifies the type of compression, usually set to zero (no compression).
35 4 biSizeImage 0 specifies the size of the image data, in bytes. If there is no compression, it is valid to set this member to zero.
39 4 biXPelsPerMeter 0 specifies the the horizontal pixels per meter on the designated targer device, usually set to zero.
43 4 biYPelsPerMeter 0 specifies the the vertical pixels per meter on the designated targer device, usually set to zero.
47 4 biClrUsed 0 specifies the number of colors used in the bitmap, if set to zero the number of colors is calculated using the biBitCount member.
51 4 biClrImportant 0 specifies the number of color that are 'important' for the bitmap, if set to zero, all colors are important.

 

 요런 구조로 되어 있군요..

 이런 구조구조체로 작성해서 파일을 연후.. 구조체 크기만큼 읽으면

 헤더만 딱 읽어 낼수 있습니다...

 

 그리고 헤더를 제외한 나머지 data부분이 raw Data이죠..

 헤더크기를 계산해서(대충 계산해 보니 54byte 네요)

  fseek 으로 헤더크기만큼 이동한후

 그 이후부터의 데이터만 읽어도 되구요...

 

 BMP 파일파일구조(포멧)에 대해서 공부해 보세요 ^^;