BMP 그림 의 데이터 구조

5687 단어 잡담
작은 공책 으로 적어 라
#include"stdio.h"
#include
#include
//                 
struct BITMAPFILEHEADER
{
    byte bfType;/*    */
    DWORD bfSize;/*    ,      */
    byte bfReserved1;
    byte bfReserved2;
    DWORD bfOffBits;/*                */
};
struct BITMAPINFOHEADER
{
    DWORD biSize;/*          */
    LONG biWidth;/*    ,      */
    LONG biHeight;/*    ,      */
    byte biPlanes;
    byte biBitCount;/*     , 1 4 8 24*/
    DWORD biCompression;/*     0    */
    DWORD biSizeImage;
    LONG biXPelsPerMeter;
    LONG biYPelsPerMeter;
    DWORD biClrUsed;
    DWORD biClrImportant;/*     ,0     */
};
struct RGB_QUAD
{
    byte rgbBlue;/*    */
    byte rgbGreen;/*    */
    byte rgbRed;/*    */
    byte rgbReversed;/*   */
};
struct RGB_QUAD img[1000][1000];//     1000*1000

int main(void)
{
    BITMAPFILEHEADER fileHeader;//       
    BITMAPINFOHEADER infoHeader;//       

    printf("Please indicate the path and filename of the input image(For example:F:\\in.bmp): ");
    char str_in[100];
    memset(str_in,'\0',sizeof(str_in));
    scanf("%s",str_in);
    printf("Please indicate the path and filename of the output image(For example:F:\\out.bmp): ");
    char str_out[100];
    memset(str_out,'0',sizeof(str_out));
    scanf("%s",str_out);

    FILE *pfin=fopen(str_in,"rb");//      
    FILE *pfout=fopen(str_out,"wb");//      

    fread(&fileHeader,sizeof(BITMAPFILEHEADER),1,pfin);//          
    fread(&infoHeader,sizeof(BITMAPINFOHEADER),1,pfin);//          

    if(infoHeader.biBitCount==4)//   16  
    {
        int size=infoHeader.biWidth*infoHeader.biHeight;
        fread(img,sizeof(struct RGB_QUAD),size,pfin);//      

        int i,j;
        for(i=0; i//     
        {
            for(j=0; j3;
                img[i][j].rgbGreen=img[i][j].rgbGreen<<2;
                img[i][j].rgbRed=img[i][j].rgbRed<<3;
                img[i][j].rgbBlue=img[i][j].rgbGreen=img[i][j].rgbRed=img[i][j].rgbBlue*0.11+img[i][j].rgbGreen*0.59+img[i][j].rgbRed*0.30;
            }
        }

        fwrite(&fileHeader,sizeof(fileHeader),1,pfout);//     
        fwrite(&infoHeader,sizeof(infoHeader),1,pfout);//     
        fwrite(img,sizeof(struct RGB_QUAD),size,pfout);//      
    }
    else
    {
        printf("    16 BMP 
"
); } fclose(pfin);// fclose(pfout); return 0; }

좋은 웹페이지 즐겨찾기