Thread: Writing Bitmap Files

  1. #1

    Writing Bitmap Files

    I'm having a problem writing the code for writing a .bmp file. What I'm trying to do right now is load a bitmap then use that same information and write it into another file. The problem is, the first 10 lines or so of pixels in the image I write ends up completely black... I need help =/. Here's the code I'm using.

    BITMAPINFOHEADER bmpiheader;//Info header
    BITMAPFILEHEADER bmpfheader;//File header
    unsigned int bbuffer[2048]; //holds the image (64x32x32bit)
    FILE *fptr; //file pointer
    fptr=fopen("first.bmp","rb"); //opens original bitmap in binary
    //Reads the header information into the headers
    //Reads the image into bbuffer
    fclose(fptr); //closes file pointer
    fptr=fopen("new.bmp,"wb");//makes new .bmp file for bin writing
    //writes in the headers I got from the other file
    //writes in the image information from the other image
    fclose(fptr); //closes file
    I can't understand why this makes the first 10 lines completely black...

  2. #2


    I figured out the problem - the bmp file was a 24-bit image, but I was treating it as a 32bit (unsigned int). I just changed my unsigned int bbuffer[2048] to unsigned char bbuffer[2048][3] (chars are 8 bit, 3 of them make 24 bit) and now it works. YAY.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with Bitmap Display
    By The Brain in forum Windows Programming
    Replies: 7
    Last Post: 03-23-2009, 05:33 AM
  2. Problems writing some chars to files with fprintf
    By Nazgulled in forum C Programming
    Replies: 3
    Last Post: 04-18-2006, 06:00 PM
  3. Writing files to a CD
    By SyntaxBubble in forum Windows Programming
    Replies: 1
    Last Post: 04-16-2003, 04:43 PM
  4. writing files to a specified folder
    By jverkoey in forum Windows Programming
    Replies: 5
    Last Post: 03-29-2003, 11:09 PM
  5. Writing to files on exact spots
    By R@m0n in forum C++ Programming
    Replies: 3
    Last Post: 02-10-2002, 06:06 AM