CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Bitmaps

  1. #1
    Join Date
    Jul 1999
    Posts
    1

    Bitmaps

    Hello

    i want to decode the bits information in a *.bmp file , only the bit , iwant to delete the color table and extension info. etc
    thanks




  2. #2
    Join Date
    May 1999
    Location
    Germany
    Posts
    106

    Re: Bitmaps

    Hi,

    hope this code helps. I didn't test it and there is no error
    handling. But it shows how to do it.
    First read the BITMAPFILEHEADER. Then read BITMAPINFO. Finaly the
    bits.

    Please write a short answer, if you have success.

    Good luck!
    Peter




    FILE *f;
    BITMAPFILEHEADER bmpfh;
    BITMAPINFO *bmpinfo=NULL;
    void *bits=NULL;
    long infosize,bitsize,widthbyte;

    // open file
    f=fopen("test.bmp","rb");

    // read the BITMAPFILEHEADER and calculate size of BITMAPINFO
    fread((void*)&bmpfh,1,sizeof(BITMAPFILEHEADER),f);
    infosize=bmpfh.bfOffBits-sizeof(BITMAPFILEHEADER);

    // read BITMAPINFO
    bmpinfo=(BITMAPINFO*)malloc(infosize));
    fread((void*)bmpinfo,1,infosize,f);

    if(bmpinfo->bmiHeader.biSizeImage==0)
    {
    widthbyte=(bmpinfo->bmiHeader.biWidth
    *bmpinfo->bmiHeader.biBitCount+7)/8;
    while(widthbyte%4) ++widthbyte;
    bitsize=widthbyte*bmpinfo->bmiHeader.biHeight;
    }
    else
    {
    bitsize=bmpinfo->bmiHeader.biSizeImage;
    }

    // read bits
    bits=malloc(bitsize);
    fread(bits,1,bitsize,f);

    // close file
    fclose(f);






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

Featured