Brauch Hilfe beim laden eines BMP Headers
-
Hi
ich möchte ein einfaches BMP einlesen, doch leider happerts da schon beim BMP header. Ich bekomm einfach nicht die richtigen Werte in meine struktur. Um den Fehler zu finden, hab ich mir einfach mal die Visual Structur BITMAPFILEHEADER als Vorbild genommen, und die einfach nachgebaut, doch leider funktionierts auch mit der nicht.
typedef unsigned char byte; typedef unsigned short int word; typedef unsigned long dword; typedef struct st_bmpheader { word w_signatur; dword dw_size; word w_reserved1; word w_reserved2; dword dw_dataoffset; }st_bempheader1; BITMAPFILEHEADER Header; st_bmpheader header; fseek(pf_file,0,0); fread(&header,sizeof(st_bmpheader),1,pf_file); fseek(pf_file,0,0); fread(&Header,sizeof(BITMAPFILEHEADER),1,pf_file);Meine struktur (st_bempheader) hat die selben Variablen also vom gleichen Typ, wie BITMAPFILEHEADER, allerdings lese ich mit der BITMAPFILEHEADER Struktur gültige Werte ein und mit meiner nicht. Um das noch zu toppen, liefert meine Struktur bei einem sizeof() den wert 16 und die BITMAPFILEHEADER 14.
WIE? && WARUM?
-
du solltest dir schon die gesamte Struktur zum Vorbild nehmen:
#include <pshpack2.h> typedef struct tagBITMAPFILEHEADER { WORD bfType; DWORD bfSize; WORD bfReserved1; WORD bfReserved2; DWORD bfOffBits; } BITMAPFILEHEADER, FAR *LPBITMAPFILEHEADER, *PBITMAPFILEHEADER; #include <poppack.h>und pshpack2.h sieht so aus:
/*++ Copyright (c) Microsoft Corporation. All rights reserved. Module Name: pshpack2.h Abstract: This file turns 2 byte packing of structures on. (That is, it disables automatic alignment of structure fields.) An include file is needed because various compilers do this in different ways. For Microsoft compatible compilers, this files uses the push option to the pack pragma so that the poppack.h include file can restore the previous packing reliably. The file poppack.h is the complement to this file. --*/ #if ! (defined(lint) || defined(RC_INVOKED)) #if ( _MSC_VER >= 800 && !defined(_M_I86)) || defined(_PUSHPOP_SUPPORTED) #pragma warning(disable:4103) #if !(defined( MIDL_PASS )) || defined( __midl ) #pragma pack(push,2) #else #pragma pack(2) #endif #else #pragma pack(2) #endif #endif // ! (defined(lint) || defined(RC_INVOKED))und poppack.h:
/*++ Copyright (c) Microsoft Corporation. All rights reserved. Module Name: poppack.h Abstract: This file turns packing of structures off. (That is, it enables automatic alignment of structure fields.) An include file is needed because various compilers do this in different ways. poppack.h is the complement to pshpack?.h. An inclusion of poppack.h MUST ALWAYS be preceded by an inclusion of one of pshpack?.h, in one-to-one correspondence. For Microsoft compatible compilers, this file uses the pop option to the pack pragma so that it can restore the previous saved by the pshpack?.h include file. --*/ #if ! (defined(lint) || defined(RC_INVOKED)) #if ( _MSC_VER >= 800 && !defined(_M_I86)) || defined(_PUSHPOP_SUPPORTED) #pragma warning(disable:4103) #if !(defined( MIDL_PASS )) || defined( __midl ) #pragma pack(pop) #else #pragma pack() #endif #else #pragma pack() #endif #endif // ! (defined(lint) || defined(RC_INVOKED))d.h. um deine struktur fehlt ein #pragma pack(push,2) davor und ein #pragma pack(pop) danach.
-
aha, seltsam, ich habe die
pshpack2.h oder poppack.h
eigentlich nicht gebraucht um das programm zu kompilieren.
wdw. was bedeutet
#pragma pack(push,2) und #pragma pack(pop) ?
-
{
CBitmap TempBMP;
BITMAP BMPHeader;HBITMAP hBmp = (HBITMAP)::LoadImage( NULL, "bilddatei", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION);
if(hBmp != NULL)
{
TempBMP.Attach(hBmp);
TempBMP.GetBitmap(BMPHeader))
}
}
// in der BMPHeader sind nun alle infos inkl. die Pixel.leider hatte ich oft das problem, dass ich nicht alle BMP laden konnte.
musste sie dann erst mit PSP (PaintShopPro) laden und dann speicher unter ...
hmm ?? weiss ich auch nicht woran das lag ??wie auch immer
vieleicht hilft es dir jagruß
volkerGruß
Volker