출처 : 네이버 지식인
제가 알기론 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 파일의 파일구조(포멧)에 대해서 공부해 보세요 ^^;
'김탱 개발자 > C/C++' 카테고리의 다른 글
외부 클래스 추가 시 Add Files 안 먹힐때 (0) | 2014.12.05 |
---|---|
raw파일 읽고 쓰는 기본 소스 (링크) (0) | 2014.07.10 |
raw파일 읽는법 (0) | 2014.07.10 |
C언어 동적할당 calloc, realloc 함수 (링크) (0) | 2014.07.10 |
C언어 동적할당 malloc 함수 (링크) (0) | 2014.07.10 |