Thread: write bmp

  1. #16
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,674
    > fout << pixel;
    So, when did this lose the subscripts.

    I'm saying this a lot at the moment, fix your indentation of the code - it's horrible to follow.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  2. #17
    Registered User
    Join Date
    Sep 2006
    Posts
    18
    Sorry about the messy code. I'm just trying so much stuff, and was planning on fixing the format once it was working. Should've made it tidy before posting, so apologies there. I tried creating a dynamic array but it's not working. The problem seems to be that once I've written to the file in my for loop, I can no longer access the pixels (or at least write to them again). I need to have the for loop in order to set the background to a colour otherwise the bitmap would just have the header and no image data.

    edit: I've edited the original code to make it (slightly) more legible.
    Thanks

  3. #18
    Registered User
    Join Date
    Sep 2006
    Posts
    18
    I would have thought that this would keep the value of i constant. In turn, there should only be one pixel drawn. However, even though this is the only for loop in the program, it still makes the whole bitmap blue. This is probably why my pixels aren't drawing individually.
    Code:
    for (int j=699); j >=0 ; j--){ 
           for (int l=0; l<700; l++){
    
    
                     int i = 6;
    
                     pixel[i + BLUE_OFF] = 0xFF;
                     pixel[i + GREEN_OFF] = 0;
                     pixel[i + RED_OFF] = 0;
                     fout << pixel[i + BLUE_OFF] ;
                     fout << pixel[i + GREEN_OFF];
                     fout << pixel[i + RED_OFF] ;
    
            }
    }

  4. #19
    Registered User
    Join Date
    Sep 2006
    Posts
    18
    After days of head banging, I've fianlly managed to solve the problem. Thanks everyone for your help, I really appreciate it. Now to complete the main part of the project lol.
    Thanks again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading BMP
    By Mortissus in forum C Programming
    Replies: 4
    Last Post: 02-02-2006, 06:32 AM
  2. Reroute where programs write to
    By willc0de4food in forum C Programming
    Replies: 7
    Last Post: 09-21-2005, 04:48 PM
  3. Strange problem with bmp
    By Victor in forum Linux Programming
    Replies: 2
    Last Post: 04-04-2005, 02:48 PM
  4. adding encryption to bmp
    By GiraffeMan in forum C Programming
    Replies: 10
    Last Post: 04-16-2002, 01:42 PM
  5. write in c
    By PutoAmo in forum C Programming
    Replies: 6
    Last Post: 04-03-2002, 07:53 PM