English 中文(简体)
在阅读比图图图像时收集错误数据
原标题:Getting wrong data while reading Bitmap image
  • 时间:2012-05-02 07:55:19
  •  标签:
  • c++
  • graphics

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宣布了储存光标头的结构。

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;

之后,我通过使用以下代码读了比图:

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

    if (in == NULL)
    {
        printf("Error opening file
");
    }
    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");
    }

我的情况是24点,但当我管理这一方案时,它显示“不是24点”。 我试图在视觉演播室一中进行推测,然后看到<条码>bmih.biBitCount<0>。 此外,图像宽度和高度也是错误的,我在头部发现的唯一正确数据是bmfh.bfType。 页: 1

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?

最佳回答

我想,你会进入alignment issue,因为汇编者可以选择在他认为合适的结构中统一数据。 你可以尝试包罗你的脚石,但我建议宣读每一个领域,单独填满,这项工作更多,但更清楚,避免了一致性问题。

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签