Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7866173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:18:47+00:00 2026-06-03T00:18:47+00:00

I’m following this tutorial http://www.gamedev.net/page/resources/_/technical/game-programming/how-to-load-a-bitmap-r1966 and I got the problem of wrong value for

  • 0

I’m following this tutorial
http://www.gamedev.net/page/resources/_/technical/game-programming/how-to-load-a-bitmap-r1966 and I got the problem of wrong value for all the bitmap header/info that I load.

I’ve declared the structure to store the bitmap header, info

typedef struct BITMAPFILE_HEADER {
  WORD  bfType;
  DWORD   bfSize;
  WORD  bfReserved1;
  WORD  bfReserved2;
  DWORD   bfOffBits;
} BITMAPFILE_HEADER;

//Bitmap information header
//provides information specific to the image data
typedef struct BITMAPINFO_HEADER{
  DWORD  biSize;
  LONG   biWidth;
  LONG   biHeight;
  WORD   biPlanes;
  WORD   biBitCount;
  DWORD  biCompression;
  DWORD  biSizeImage;
  LONG   biXPelsPerMeter;
  LONG   biYPelsPerMeter;
  DWORD  biClrUsed;
  DWORD  biClrImportant;
} BITMAPINFO_HEADER;

//Colour palette
typedef struct RGB_QUAD {
  BYTE  rgbBlue;
  BYTE  rgbGreen;
  BYTE  rgbRed;
  BYTE  rgbReserved;
} RGB_QUAD;

After that I read the bitmap by using following codes:

    FILE *in;
    in = fopen("picture.bmp", "rb");

    if (in == NULL)
    {
        printf("Error opening file\n");
    }
    else
    {
        BITMAPFILE_HEADER bmfh;
        BITMAPINFO_HEADER bmih;

        fread(&bmfh, sizeof(BITMAPFILE_HEADER), 1, in);
        fread(&bmih, sizeof(BITMAPINFO_HEADER), 1, in);

        if (bmih.biBitCount != 24)
            printf("not 24");
    }

My picture is 24-bit but when I run this program, it shows “not 24”. I try to debug it in Visual Studio then I saw the bmih.biBitCount is 0. In addition, the image width and height is wrong as well, the only correct data that I found in the header is the bmfh.bfType which is 19778.

Anyone know what’s wrong with my codes?
Again, I just want to read the bmp but not displaying it.

PS:
Originally the picture is in JPEG format. I converted it to BMP format by using MS PAINT and re-save it in BMP format. I wonder does it affect the values?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:18:48+00:00Added an answer on June 3, 2026 at 12:18 am

    I would imagine that you ran into an alignment issue, because the compiler can choose to align data in a structure as he sees fit. You can try to pack your struct, but I would suggest to read out every field and fill it in separately, it is more work, but it is clearer and avoids alignment issues.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.