need C program help

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Feb 2008
Posts: 9
Reputation: rockmania is an unknown quantity at this point 
Solved Threads: 0
rockmania rockmania is offline Offline
Newbie Poster

need C program help

 
0
  #1
Apr 5th, 2008
I need C code or program to save the output of the following program into a jpg file(any picture file)?
i need to save the output of this program in to a picture file..i need to take printouts of those output..help me with the code that does the above thing...
this program is just a program to draw straight line using DDA algorithm
  1. #include<graphics.h>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<conio.h>
  5. #include<dos.h>
  6. #define ROUND(a)((int)(a+0.5))
  7. void dda(int,int,int,int);
  8. void main()
  9. {
  10. int gdriver=DETECT,gmode;
  11. int x1,y1,x2,y2;
  12. initgraph(&gdriver,&gmode,"c:\\tc\\bgi...
  13. printf("Enter the starting and ending coordinates of line:");
  14. scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
  15. dda(x1,y1,x2,y2);
  16. getch();
  17. }
  18. void dda(int xa,int ya,int xb,int yb)
  19. {
  20. int dx,dy,steps,k;
  21. float xinc,yinc,x,y;
  22. dx=xb-xa;
  23. dy=yb-ya;
  24. if(abs(dx)>abs(dy))
  25. steps=abs(dx);
  26. else
  27. steps=abs(dy);
  28. xinc=dx/(float)steps;
  29. yinc=dy/(float)steps;
  30. x=xa;
  31. y=ya;
  32. putpixel(ROUND(x),ROUND(y),1);
  33. for(k=1;k<=steps;k++)
  34. {
  35. x=x+xinc;
  36. y=y+yinc;
  37. delay(10);
  38. putpixel(ROUND(x),ROUND(y),1);
  39. }
  40. }
  41.  
Last edited by Ancient Dragon; Apr 5th, 2008 at 9:44 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 327
Reputation: Colin Mac is on a distinguished road 
Solved Threads: 22
Colin Mac Colin Mac is offline Offline
Posting Whiz

Re: need C program help

 
0
  #2
Apr 5th, 2008
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,594
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1487
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: need C program help

 
0
  #3
Apr 5th, 2008
You have to use TurboC or TurboC++ compilers to use either of those links. graphics.h is obsolete and not supported by all other compilers.

I don't really know the answer to the question but I think it will be pretty complicated. Here is the jpg file format and here are other possible google links that may be useful.
Last edited by Ancient Dragon; Apr 5th, 2008 at 10:29 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 319
Reputation: Luckychap is on a distinguished road 
Solved Threads: 42
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Posting Whiz

Re: need C program help

 
0
  #4
Apr 6th, 2008
I think you must choose .bmp file instead of jpg, as jpg files are difficiult to read and hence write. On the other hand .bmp files are easy to read and write. But they take much more strorage as compared to jpg files (no compression in .bmp files). you should go for 4-bits .bmp file. I can tell you its all about the header of bmp file, onces you understand the header its easy to read and write the file.

Best of luck
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 9
Reputation: rockmania is an unknown quantity at this point 
Solved Threads: 0
rockmania rockmania is offline Offline
Newbie Poster

Re: need C program help

 
0
  #5
Apr 6th, 2008
http://www.cs.colorado.edu/~main/cs1.../getimage.html
this link was very useful
the thing is where do the image gets stored....that is the location...
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
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: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: need C program help

 
0
  #6
Apr 6th, 2008
It gets stored in a memory block of your choice.
You then need to write that out to a BMP file, along with the correct BMP header.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC