Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

c programing

Options
  • 04-12-2012 11:35am
    #1
    Registered Users Posts: 47


    any1 write an example c program to scan an image file to see if its a solid (all black) or a ring (black with a white circle in the middle). Cheers!


Comments

  • Registered Users Posts: 406 ✭✭Gotham


    Is this a college project?

    When you load a bmp into a char[], you can run through it like this:

    for (int y=0;y<lengthy;y++)
    {
    for (int x=0;x<lengthx;x+=3)
    {
    char red = char[x+(lengthx*y)];
    char green= char[x+(lengthx*y)+1];
    char blue = char[x+(lengthx*y)+2];
    if (red == green == blue == 255)
    {
    //this is black
    }
    }
    }

    this is off the top of my head, but i think it should be correct for the body of the processing.


  • Registered Users Posts: 47 paddyd8


    Thanks but what i hav that bit done. What I need is a while loop that starys at the top of the image scan down througj it and see if its a solid or a ring?


  • Registered Users Posts: 406 ✭✭Gotham


    paddyd8 wrote: »
    Thanks but what i hav that bit done. What I need is a while loop that starys at the top of the image scan down througj it and see if its a solid or a ring?
    The code i provided scns through it.

    Whenever you come across a white pixel, calculate its distance to the center of the image. Add this distance to a global number and count the number of white pixels you have scanned.
    Average the global number out and use a tolerance (for aliasing) to check if the white pixels average out to be in the center of the image.


  • Registered Users Posts: 47 paddyd8


    so will your example code do this?


  • Registered Users Posts: 7,501 ✭✭✭BrokenArrows


    Sounds me me like someone wants their homework done.


  • Advertisement
  • Registered Users Posts: 406 ✭✭Gotham


    paddyd8 wrote: »
    so will your example code do this?

    No

    The lecturers all check these sites btw. They also check those sites where you pay people to do their projects for you. I know many people personally who were caught out, and all it takes is one post that has too much info in it.

    I've given you code and a description of a very do-able solution, it's not that hard and it's not that much work. I'm not going to get you in trouble, seeing as you're already traceable enough.


Advertisement