943,789 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 903
  • C RSS
Apr 5th, 2008
0

need C program help

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rockmania is offline Offline
9 posts
since Feb 2008
Apr 5th, 2008
0

Re: need C program help

Reputation Points: 78
Solved Threads: 22
Posting Whiz
Colin Mac is offline Offline
327 posts
since Sep 2006
Apr 5th, 2008
0

Re: need C program help

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Apr 6th, 2008
0

Re: need C program help

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
Reputation Points: 83
Solved Threads: 61
Posting Pro in Training
Luckychap is offline Offline
442 posts
since Aug 2006
Apr 6th, 2008
0

Re: need C program help

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...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rockmania is offline Offline
9 posts
since Feb 2008
Apr 6th, 2008
0

Re: need C program help

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.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: need help with c
Next Thread in C Forum Timeline: Insertion sort with files





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC