954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

need C program help

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

#include<graphics.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<dos.h>
#define ROUND(a)((int)(a+0.5))
void dda(int,int,int,int);
void main()
{
int gdriver=DETECT,gmode;
int x1,y1,x2,y2;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi...
printf("Enter the starting and ending coordinates of line:");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
dda(x1,y1,x2,y2);
getch();
}
void dda(int xa,int ya,int xb,int yb)
{
int dx,dy,steps,k;
float xinc,yinc,x,y;
dx=xb-xa;
dy=yb-ya;
if(abs(dx)>abs(dy))
steps=abs(dx);
else
steps=abs(dy);
xinc=dx/(float)steps;
yinc=dy/(float)steps;
x=xa;
y=ya;
putpixel(ROUND(x),ROUND(y),1);
for(k=1;k<=steps;k++)
{
x=x+xinc;
y=y+yinc;
delay(10);
putpixel(ROUND(x),ROUND(y),1);
}
}
rockmania
Newbie Poster
9 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 
Colin Mac
Posting Whiz
327 posts since Sep 2006
Reputation Points: 78
Solved Threads: 22
 

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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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

Luckychap
Posting Pro in Training
444 posts since Aug 2006
Reputation Points: 83
Solved Threads: 61
 

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...

rockmania
Newbie Poster
9 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

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.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You