Help in C program (Image reading)

Reply

Join Date: Apr 2008
Posts: 7
Reputation: Iphicles is an unknown quantity at this point 
Solved Threads: 0
Iphicles Iphicles is offline Offline
Newbie Poster

Help in C program (Image reading)

 
0
  #1
Apr 22nd, 2008
Hi, can anyone out help me with my assignment which is to read an image file of a maze and find an exit of it.

As I'm still kinda of new @ C programming, I'm having problems even reading the image onto C.

Cheers
Ming
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,851
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Help in C program (Image reading)

 
0
  #2
Apr 23rd, 2008
Well what format is this image file in?
BMP format perhaps?

Though most newbies start with mazes defined in ascii art, like this
  1. #S########
  2. # #
  3. ###### #
  4. # #
  5. #E########
Find a route through the maze from S to E
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 7
Reputation: Iphicles is an unknown quantity at this point 
Solved Threads: 0
Iphicles Iphicles is offline Offline
Newbie Poster

Re: Help in C program (Image reading)

 
0
  #3
Apr 23rd, 2008
Salem the image will be of .gif or .bmp format. I can't seems to even find the correct library or codes to even load it.

Cheers
Ming
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,851
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Help in C program (Image reading)

 
0
  #4
Apr 23rd, 2008
http://www.wotsit.org/
BMP is dead easy, it's little more than a screen dump of pixels.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 7
Reputation: Iphicles is an unknown quantity at this point 
Solved Threads: 0
Iphicles Iphicles is offline Offline
Newbie Poster

Re: Help in C program (Image reading)

 
0
  #5
Apr 24th, 2008
Salem, after reading all of the web page contents, I'm still having problems even writing out the initial program.

Cos i not so sure which library to use, for normal standard program is #include Studio.h or math.h for calculation etc.

But for this instance, I am getting more confuse. Please advice me about how to go about writing the program. If its possible, can you show me examples instead.

Cheers
ming
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,851
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Help in C program (Image reading)

 
0
  #6
Apr 24th, 2008
Perhaps start with an ASCII-art map like I posted above, and then develop the maze solving code.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 326
Reputation: Colin Mac is on a distinguished road 
Solved Threads: 22
Colin Mac Colin Mac is offline Offline
Posting Whiz

Re: Help in C program (Image reading)

 
0
  #7
Apr 24th, 2008
Do you know about C File I/O?

This is the .bmp format.
http://www.fortunecity.com/skyscrape.../bmpffrmt.html
Open a bitmap in a hex editor as you follow it along.

Then extract the data you want. That's the easy part done.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 7
Reputation: Iphicles is an unknown quantity at this point 
Solved Threads: 0
Iphicles Iphicles is offline Offline
Newbie Poster

Re: Help in C program (Image reading)

 
0
  #8
Apr 28th, 2008
Colin,

I tried reading that webpage many time and I still don't have the slightest idea about how to go about it.

Is it possible that U can write a little portion about how to read an .bmp file script for me to take a look and its easier for me to understand.

Cheers
Ming
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,851
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Help in C program (Image reading)

 
0
  #9
Apr 28th, 2008
FILE *fp = fopen( "file.bmp", "rb" ); This opens the file

unsigned char buff[10];
size_t n = fread( buff, sizeof(buff[0]), sizeof(buff), fp );
This reads 10 bytes from the file.

10 is obviously just an example, but you can read the documentation to find out how big a BMPHEADER structure is, and read that number of bytes instead. Having got that, you get vital information such as
- the width and height of the image
- the number of bits in each pixel
- whether there is a colour table in the file.

You then skip the optional colour table (say by using fseek), then you can start looping reading image data, based on your knowledge of the width, height and bpp of the image format.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 7
Reputation: Iphicles is an unknown quantity at this point 
Solved Threads: 0
Iphicles Iphicles is offline Offline
Newbie Poster

Re: Help in C program (Image reading)

 
0
  #10
Apr 28th, 2008
Salem, Thanks for getting back to me on this. But when U say

unsigned char buff[10];
size_t n = fread( buff, sizeof(buff[0]), sizeof(buff), fp );
This reads 10 bytes from the file.


Do U mean that this command only allow me to read only 10bytes of data from the file only?

And the .bmp file i'm reading is simply in black and white.

Pls look at http://hereandabove.com/maze/mazeorig.form.html.

And u will have a clearer idea what sort of image i'm trying to read.

Cheers & Thanks
Ming
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC