Results 1 to 5 of 5

Thread: Error Unable to load bitmap file

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    8

    Error Unable to load bitmap file

    Hi,
    I have a program that generates bitmaps and another to display them. The display program works fine on bitmaps I cerate manually with paint, but when my other program generates them and I try to load them I get the error unable to load bitmap message.

    My program creating bitmaps makes 512x512 24 bit color bmps. Coula anyone tell me what might be wrong?

    Thanks

    Tim

  2. #2
    Member Contributor
    Join Date
    Aug 2001
    Posts
    62

    Re: Error Unable to load bitmap file

    how are you writing the headers?

    what info are you writing as the bitmap header?

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    8

    Re: Error Unable to load bitmap file

    Sorry for the late response,

    I use:


    // File header
    m_pBmpFileHeader = new BITMAPFILEHEADER;
    m_pBmpFileHeader->bfType = 0x4d42;
    m_pBmpFileHeader->bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFO) + dwImgSize;
    m_pBmpFileHeader->bfReserved1 = 0;
    m_pBmpFileHeader->bfReserved2 = 0;
    m_pBmpFileHeader->bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFO) + sizeof(RGBQUAD);

    // Bitmap Info header
    m_pBmpInfo = new BITMAPINFO;
    m_pBmpInfoHeader = reinterpret_cast<LPBITMAPINFOHEADER>(m_pBmpInfo);
    ::ZeroMemory(m_pBmpInfoHeader, sizeof(BITMAPINFOHEADER));
    m_pBmpInfoHeader->biSize = sizeof(BITMAPINFOHEADER);
    m_pBmpInfoHeader->biWidth = Bitmap.bmWidth;
    m_pBmpInfoHeader->biHeight = Bitmap.bmHeight;
    m_pBmpInfoHeader->biPlanes = 1;
    m_pBmpInfoHeader->biBitCount = Bitmap.bmPlanes * Bitmap.bmBitsPixel;
    m_pBmpInfoHeader->biSizeImage = dwImgSize;


    This code is executed in a create(&bitmap) function, but I did not write it myself so I am not too clear on it.

    Thanks

    Tim

  4. #4
    Member Contributor
    Join Date
    Aug 2001
    Posts
    62

    Re: Error Unable to load bitmap file

    here's what i ended up writing about 2 years ago, when i wrote a custom loader/saver.

    Code :
     
    typedef struct
    {
    	DWORD Filesize;		// Filesize in bytes of bitmap
    	DWORD Reserved;
    	DWORD DataOffset;	// Offset To Actual Bitmap Data
    	DWORD HeaderSize;	// Size Of the Bitmap Header
    	DWORD Width;		// Width In Pixels
    	DWORD Height;		// Height In Pixels
    	WORD Planes;
    	WORD BitsPerPixel;	// Bits Per Pixel
    	DWORD Compression;
    	DWORD DataSize;		// Size Of the Bitmap Data
    	DWORD HPPM;			// Horizontal Pixels Per Meter
    	DWORD VPPM;			// Vertical Pixels Per Meter
    	DWORD Colors;		// Colors Used In Bitmap
    	DWORD IColors;		// Important Colors
    }BmpHeader;
     
    BmpHeader header;
    char FileType[2];
     
    Fill the header:
     
    FileType[0] = 'B';
    FileType[1] = 'M';
    header.DataOffset = 54;		// this is about the only offset that actually works
    header.Filesize = 0x28 + (the file's size - the header) or (the width * height * (bits per pixel/8);
    header.HeaderSize = 0x28;	// 40 represents the true size of the header 
    header.Height = the height;
    header.Width = the width;
    header.HPPM = 2952;			// 75 Horizontal Pixels Per Meter
    header.VPPM = 2952;			// 75 Vertical Pixels Per Meter
    header.BitsPerPixel = 24;    // unless your compressing it 24 should do
    header.Colors = 0;
    header.IColors = 0;
    header.Planes = 1;
    header.Reserved = 0;
    header.Compression = 0;
     
    Write Code:
     
    FILE* fp = fopen(filename,wb);
     
    // write the type
    fwrite(FileType,2,1,fp);
    // write the full header
    fwrite(&amp;header,sizeof(BmpHeader),1,fp);
    // then write the data.
    fwrite(data,datasize,1,fp);

    [This message has been edited by no-one (edited 07-09-2002).]

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    8

    Re: Error Unable to load bitmap file

    Thanks for the help

Similar Threads

  1. Error unable to open file while loading textures
    By ejgutierrez in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-25-2015, 09:36 AM
  2. load bitmap file problem
    By in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 02-15-2005, 07:03 AM
  3. How to Load A Bitmap From File
    By Stack Overflow in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 12-13-2002, 07:17 AM
  4. Replies: 2
    Last Post: 12-20-2001, 09:31 AM
  5. How to load bitmap file
    By in forum OpenGL: Linux
    Replies: 1
    Last Post: 09-11-2001, 03:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean