melzeiny
April 16th, 2008, 09:19 AM
Hi All,
I am new in C++ programming, and I got this sample code from the internet to draw a bar chart , however . I need instead of drawing this chart on the screen I need to export it to ANY image format what so ever on my hard disk. Any one?? :D
here is the sample code
//Author: Karanth Srihari
//Email ID: hari_karanth@indiatimes.com
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
int values[10],n;
void ingraph()
{
int i;
setbkcolor(9);
settextstyle(4,0,5);
outtextxy(160,5,"BAR GRAPH");
settextstyle(3,0,2);
outtextxy(300,450,"X-AXIS");
settextstyle(3,1,2);
outtextxy(30,200,"Y-AXIS");
line(100,60,100,400);
line(100,400,500,400);
for(i=120;i<500;i+=20)
line(i,400,i,405);
for(i=300;i>60;i-=20)
line(100,i,95,i);
line(500,398,500,402);
line(504,400,500,398);
line(500,402,504,400);
line(98,60,102,60);
line(100,56,98,60);
line(100,56,102,60);
}
drawgraph()
{
int i,j;
for(i=0,j=115;i<n;j+=20,i++)
rectangle(j,(400-values[i]),(j+12),400);
}
void main()
{
int d=0,m=0,i;
clrscr();
initgraph(&d,&m,"c:\\tc");
printf("ENTER NUMBER OF OBJECTS::\n");
scanf("%d",&n);
printf("ENTER THE VALUES::\n");
for(i=0;i<n;i++)
scanf("%d",&values[i]);
cleardevice();
ingraph();
drawgraph();
getch();
closegraph();
}
I am new in C++ programming, and I got this sample code from the internet to draw a bar chart , however . I need instead of drawing this chart on the screen I need to export it to ANY image format what so ever on my hard disk. Any one?? :D
here is the sample code
//Author: Karanth Srihari
//Email ID: hari_karanth@indiatimes.com
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
int values[10],n;
void ingraph()
{
int i;
setbkcolor(9);
settextstyle(4,0,5);
outtextxy(160,5,"BAR GRAPH");
settextstyle(3,0,2);
outtextxy(300,450,"X-AXIS");
settextstyle(3,1,2);
outtextxy(30,200,"Y-AXIS");
line(100,60,100,400);
line(100,400,500,400);
for(i=120;i<500;i+=20)
line(i,400,i,405);
for(i=300;i>60;i-=20)
line(100,i,95,i);
line(500,398,500,402);
line(504,400,500,398);
line(500,402,504,400);
line(98,60,102,60);
line(100,56,98,60);
line(100,56,102,60);
}
drawgraph()
{
int i,j;
for(i=0,j=115;i<n;j+=20,i++)
rectangle(j,(400-values[i]),(j+12),400);
}
void main()
{
int d=0,m=0,i;
clrscr();
initgraph(&d,&m,"c:\\tc");
printf("ENTER NUMBER OF OBJECTS::\n");
scanf("%d",&n);
printf("ENTER THE VALUES::\n");
for(i=0;i<n;i++)
scanf("%d",&values[i]);
cleardevice();
ingraph();
drawgraph();
getch();
closegraph();
}