Like Tree1Likes
  • 1 Post By Malcolm McLean

What's wrong with this code to resize a bmp file?

This is a discussion on What's wrong with this code to resize a bmp file? within the C Programming forums, part of the General Programming Boards category; Hi. I'm trying to work through Harvard's open source computer science class, and one piece of code I have to ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    23

    What's wrong with this code to resize a bmp file?

    Hi. I'm trying to work through Harvard's open source computer science class, and one piece of code I have to write is to resize a bmp file. I spent most of the day digesting through the code, and learning it from analyzing ( https://code.google.com/p/danieleuge...ad1b662c368477 ). However, in the code I just linked to, when I run it, only a portion of the image shows up instead of the whole image.

    Why is that? What is being messed up? Thank you!

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,418
    Which OS and compiler are you using?

    If you're on windows, your file modes need to be "rb" and "wb"
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    23
    Hi Salem! I'm using Ubuntu and running it on terminal.

  4. #4
    Registered User
    Join Date
    May 2012
    Posts
    333
    Quote Originally Posted by Rubik View Post
    Hi Salem! I'm using Ubuntu and running it on terminal.
    Rather than debug your code, I'll tell you how to debug your code.

    Firstly, is the bmp write routine working as expected? What happens if you write an all-black image 32x32? Is 1x1 read correctly by other software. What about other sizes.

    After those tests, change the program so that it is reading a file and writing exactly the same data, with no processing. Are the resulting files always read correctly? If not, at what point does the saved file differ from the original in its binary image?

    If the second test isn't working but you can find nothing wrong with the write is the bmp read routine working correctly? Once you've got the write working correctly, it's a lot easier to test the read, but you can read in trivial bitmaps and test that you get the right result.

    Once the read and write work, the bug must be in the processing step. So again, test it first with trivial test images like 1x1 all black, and easy resizes liek a factor of 2, then gradually increase the complexity of the tests.
    AndiPersti likes this.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    http://www.malcolmmclean.site11.com/www

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help! What's wrong with my code? How do I read data from a file?
    By adonaldson15590 in forum C++ Programming
    Replies: 2
    Last Post: 04-25-2011, 05:07 PM
  2. Resize Image File???
    By stickman in forum C++ Programming
    Replies: 4
    Last Post: 09-19-2004, 11:46 AM
  3. what's wrong with the following code?
    By catalyst in forum C Programming
    Replies: 1
    Last Post: 11-07-2003, 03:30 AM
  4. Resize Dialog Box via Code :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 10-27-2002, 10:00 PM
  5. what is wrong with this code file?
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 11-21-2001, 11:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21