Thread: How to work with 2d arrays and an image file?

  1. #1
    Registered User
    Join Date
    May 2013

    How to work with 2d arrays and an image file?

    This is the first time I'm working with 2d arrays and I have to read the pixels in the input file, then store the pixel from the input image file into the array. And there is a maximum width and height of 500. If the file's too big, then I have to print an error message. Also, my array should only be filled up to the dimensions of the input image file.

    I have the code for everything up to that point but I'm not too sure how to approach this. I've defined max_width and height at the top of my file as 500 and I'm thinking of putting this part of the program into a new helper function. But I'm not completely sure how to start, I do know that the array would look something like this though:
    int array[max_height][max_width].

    I've searched for other similar questions, but I think what confuses me is: 1) the syntax of printing the error message/storing the values and 2) the values for my pixels in the input file are all in a single column; each value after the ppm format header is on a new line.

    I'd post my code up, but everything that I have up to this point doesn't really relate to this part of the assignment But I will post a snippet of what the input file looks like:

    493 401
    NOTE: First three lines are the header information for the ppm format; the numbers that follow go like this: red, green, blue, red, green, blue, etc.

    Thanks for taking the time to help! I really appreciate it.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doesn't work to save my arrays to a text file!
    By zergling in forum C Programming
    Replies: 35
    Last Post: 10-23-2010, 09:27 PM
  2. merge multiple image file into one image
    By mr_empty in forum C++ Programming
    Replies: 7
    Last Post: 12-09-2009, 02:12 PM
  3. Image rotation - doesn't always work
    By ulillillia in forum C Programming
    Replies: 12
    Last Post: 05-03-2007, 12:46 PM
  4. how to convert a bitmap image to a jpg image file using C++?
    By nomer in forum Windows Programming
    Replies: 4
    Last Post: 06-04-2006, 07:40 PM
  5. Image class - loading image file
    By GaPe in forum Windows Programming
    Replies: 2
    Last Post: 07-11-2004, 01:35 PM

Tags for this Thread