有誰知道可以在 與gcc/g ++結合使用的標準圖形庫?我只希望能夠畫出線條, 圓形,多邊形,三角形等我還想要支持字體和顏色 。與graphics.h類似的庫很值得期待。gcc/g ++基本圖形庫,與graphics.h兼容
謝謝。
有誰知道可以在 與gcc/g ++結合使用的標準圖形庫?我只希望能夠畫出線條, 圓形,多邊形,三角形等我還想要支持字體和顏色 。與graphics.h類似的庫很值得期待。gcc/g ++基本圖形庫,與graphics.h兼容
謝謝。
有完全相同的問題。但我想這就是我們使用CLI所得到的結果。
所以我只是決定寫我自己的。它是一個輸出Windows類型BMP文件的單一功能。我需要爲我的MinGW/GCC數字計算器輸出一些中間直方圖,並且我不想混淆圖書館,製作文件和所有這些。您只需將幾行代碼剪切到您的.C文件中並構建它即可。它有零外部電話,鏈接或其他。
您只需更改三個數組中的元素:紅色[],綠色[]和藍色[],使用文件名調用writeBMP()函數,您可以通過將圖像帶入畫圖來查看所做的操作,或資源管理器或其他。
你會認爲它是最愚蠢的東西,或者你見過的最天才的東西。這裏是它的源代碼:
#include <stdio.h>
#include <memory.h>
// absolute minimalist graphics support for C language
// (especially for my buddy's running MinGW/GCC)
//
// Requires no libraries, no external includes, no make files, NOTHING else required!!!
// To build right out of the box type: gcc graph.c and execute it.
//
// Instructions: Copy all of this code into your c/c++ source file (or into another *.c file and
// include it with '#include "graph.c"' keeping it in the same directory as your main program.
// Set the various values to the size of BMP you need, and its ready to go.
//
// Just call writeBMP and it will output a BMP file based on the contents of the 3 arrays below.
// note: this uses the example #1 used in the Wikipedia's BMP file article
// Programmed by Woody Stanford email: [email protected]
//global arrays to write graphics to
char red[420][140];
char green[420][140];
char blue[420][140];
// IMPORTANT: image width is required to be an even multiple of 4.
// 410 won't work, 420 will, sorry but bmp file padding requires it.
writeBMP(char *fname)
{
FILE *fptr;
long sx=420; //image width - MANUALLY SET THIS VALUE
long sy=140; //image height - MANUALLY SET THIS VALUE
long fs,is,a,b; //file size, image size, counters
//minimalist BMP file output harcoded for RGB (24 bits per pixel)
char bmp_hdr[54]={0x42,0x4D,0x46,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x36,0x00, 0x00,0x00,
0x28,0x00,0x00,0x00, 0x02,0x00,0x00,0x00, 0x02,0x00,0x00,0x00, 0x01,0x00,
0x18,0x00,0x00,0x00, 0x00,0x00,0x10,0x00, 0x00,0x00,0x13,0x0B, 0x00,0x00,
0x13,0x0B,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00};
fs=54+(sx*sy*3); //set fs to size of header + (sx * sy * 3)
is=(sx*sy*3); //set is to sx*sy*3
memcpy((void *)&bmp_hdr[2],(void *)&fs,4);
memcpy((void *)&bmp_hdr[18],(void *)&sx,4);
memcpy((void *)&bmp_hdr[22],(void *)&sy,4);
memcpy((void *)&bmp_hdr[34],(void *)&is,4);
fptr=fopen(fname,"wb");
fwrite(bmp_hdr,54,1,fptr);
for (a=0;a<sy;a++)
for (b=0;b<sx;b++)
{
fwrite(&blue[b][a],1,1,fptr);
fwrite(&green[b][a],1,1,fptr);
fwrite(&red[b][a],1,1,fptr);
}
fclose(fptr);
}
main()
{
int x,y;
printf("Just a stub main function. Use your own main function.\n\n");
/*
// Example code: (uncomment to see demo)
// sets background color to light gray and then generates the BMP file
for (y=0;y<120;y++)
for (x=0;x<420;x++)
{ red[x][y]=127; green[x][y]=127; blue[x][y]=127; }
writeBMP("woody2.bmp");
printf("Example BMP file written.\n\n");
*/
return;
}
/* HTML code for Internet Explorer page to refresh image display every 5 seconds:
<html>
<head>
<meta http-equiv="refresh" content="5">
<meta http-equiv="cache-control" content="no-store">
</head>
Your Image<br>
<center><img src="c:\woody\woody2.bmp"></center>
</html>
note: Check your browser's cache settings if it doesn't refresh right
*/
對於那些用於垃圾代碼的用戶,這裏是一個指向24位彩色BMP文件的鏈接那graph2.c出來了。沒有公牛,它就是這樣說的:https://www.mediafire.com/?om10ldfy1wxfz40 –
哦,對於那些認爲我的能力不強的人來說,請檢查一下。我寫了writeBMP()函數非常有趣,我想我會編寫一些其他函數來使用它。同樣沒有外部呼叫或引用(源中的ALLLL)。
#include <stdio.h>
#include <memory.h>
#include <math.h>
// GRAPH2.C DEMO (the original graph.c file is the reference file)
// Requires no libraries, no external includes, no make files, NOTHING else required!!!
// To build right out of the box type: gcc graph2.c and execute it.
//
// Instructions: Copy all of this code into your c/c++ source file (or into another *.c file and
// include it with '#include "graph.c"' keeping it in the same directory as your main program.
// Set the various values to the size of BMP you need, and its ready to go.
//
// Just call writeBMP and it will output a BMP file based on the contents of the 3 arrays below.
// note: this uses the example #1 used in the Wikipedia's BMP file article
// Programmed by Woody Stanford email: [email protected]
//global arrays to write graphics to
char red[420][140];
char green[420][140];
char blue[420][140];
//current draw color
char cred=0;
char cgreen=0;
char cblue=0; //use the setcolor function to access these vars, please.
// IMPORTANT: image width is required to be an even multiple of 4.
// 410 won't work, 420 will, sorry but bmp file padding requires it.
writeBMP(char *fname)
{
FILE *fptr;
long sx=420; //image width - MANUALLY SET THIS VALUE
long sy=140; //image height - MANUALLY SET THIS VALUE
long fs,is,a,b; //file size, image size, counters
//minimalist BMP file output harcoded for RGB (24 bits per pixel)
char bmp_hdr[54]={0x42,0x4D,0x46,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x36,0x00, 0x00,0x00,
0x28,0x00,0x00,0x00, 0x02,0x00,0x00,0x00, 0x02,0x00,0x00,0x00, 0x01,0x00,
0x18,0x00,0x00,0x00, 0x00,0x00,0x10,0x00, 0x00,0x00,0x13,0x0B, 0x00,0x00,
0x13,0x0B,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00};
fs=54+(sx*sy*3); //set fs to size of header + (sx * sy * 3)
is=(sx*sy*3); //set is to sx*sy*3
memcpy((void *)&bmp_hdr[2],(void *)&fs,4);
memcpy((void *)&bmp_hdr[18],(void *)&sx,4);
memcpy((void *)&bmp_hdr[22],(void *)&sy,4);
memcpy((void *)&bmp_hdr[34],(void *)&is,4);
fptr=fopen(fname,"wb");
fwrite(bmp_hdr,54,1,fptr);
for (a=0;a<sy;a++)
for (b=0;b<sx;b++)
{
fwrite(&blue[b][a],1,1,fptr);
fwrite(&green[b][a],1,1,fptr);
fwrite(&red[b][a],1,1,fptr);
}
fclose(fptr);
}
setcolor(char red, char green, char blue)
{
cred=red; cgreen=green; cblue=blue;
}
drawp(long x, long y)
{
red[x][y]=cred; green[x][y]=cgreen; blue[x][y]=cblue;
}
char getp(long x,long y, char *rred, char *rgreen, char *rblue)
{
*rred=red[x][y]; *rgreen=green[x][y]; *rblue=blue[x][y];
return blue[x][y];
}
drawline(long x1, long y1, long x2, long y2)
{
double x,y,s;
s=(double)((double)(y2-y1))/((double)(x2-x1)); //get slope of line
y=(double)y1;
for (x=0;x<((double)(x2-x1));x+=1)
{
drawp((long)(x+x1),(long)(y+y1));
y+=s;
}
}
drawcircle(long cx, long cy, long r)
{
double a=0,x=0,y=0;
for (a=0;a<(2*3.14159);a+=0.001)
{
x=cos(a)*r;
y=sin(a)*r;
drawp((long)x+cx,(long)y+cy);
}
}
main()
{
int x,y;
// set background color to light gray
// direct draw to the underlying arrays
for (y=0;y<140;y++)
for (x=0;x<420;x++)
{ red[x][y]=127; green[x][y]=127; blue[x][y]=127; }
printf("drawing a few pixels\n");
setcolor(255,0,0);
for (x=20;x<300;x+=5)
drawp(x,100);
printf("drawing lines\n");
setcolor(0,255,255);
drawline(10,70,300,10);
printf("drawing a circle\n");
drawcircle(70,70,30);
writeBMP("woody3.bmp");
printf("Example BMP file written.\n\n");
return;
}
對於哪種操作系統?對於Windows,有GDI,GDI +,OpenGL,DirectX,......此外,世界上是什麼'graphics.h'?我有一個名稱爲頭的頭文件,它是用C++編寫的GDI包裝器。誰發給你的!?! –
@Cody Gray - 「graphics.h」是DOS下的舊版Turbo C圖形。我正在編譯運行gcc 4.6.1的linux系統上的程序。 –
所以看看SDL! – paulsm4