C语言画图__并保存我画的图片

C语言画图__并保存我画的图片,第1张

加些分上去,我把代码贴上来。

/ HELLOC -- Hello, world /

#include <graphicsh>

#include <stdioh>

void save_pic(char fn,int maxx,int maxy){

typedef long LONG;

typedef unsigned char BYTE;

typedef unsigned long DWORD;

typedef unsigned short WORD;

typedef struct tagBITMAPFILEHEADER {

WORD bfType;

DWORD bfSize;

WORD bfReserved1;

WORD bfReserved2;

DWORD bfOffBits;

} BITMAPFILEHEADER;

typedef struct tagBITMAPINFOHEADER{

DWORD biSize;

LONG biWidth;

LONG biHeight;

WORD biPlanes;

WORD biBitCount;

DWORD biCompression;

DWORD biSizeImage;

LONG biXPelsPerMeter;

LONG biYPelsPerMeter;

DWORD biClrUsed;

DWORD biClrImportant;

} BITMAPINFOHEADER;

int i,j;

FILE fp;

BITMAPFILEHEADER bfh;

BITMAPINFOHEADER bif;

int color[16]={0,4,2,6,1,5,3,7,8,12,10,14,9,13,11,15};

unsigned char rgb[64]={0,0,0,0,0,0,128,0,0,128,0,0,0,128,128,0

,128,0,0,0,128,0,128,0,128,128,0,0,128,128,128,0

,192,192,192,0,0,0,225,0,0,255,0,0,0,255,255,0

,255,0,0,0,255,0,255,0,255,255,0,0,255,255,255,0};

union

{

unsigned char value;

struct

{

unsigned c1:4;

unsigned c2:4;

}color;

}mycolor;

bfhbfType=0x4d42;

bfhbfSize=153718;

bfhbfReserved1=0;

bfhbfReserved2=0;

bfhbfOffBits=118;

bifbiSize=40;

bifbiWidth=640;

bifbiHeight=480;

bifbiPlanes=1;

bifbiBitCount=4;

bifbiCompression=0;

bifbiSizeImage=0;

bifbiXPelsPerMeter=0;

bifbiYPelsPerMeter=0;

bifbiClrUsed=0;

bifbiClrImportant=0;

fp=fopen(fn,"wb");

fwrite(&bfh,sizeof(bfh),1,fp);

fwrite(&bif,sizeof(bif),1,fp);

fwrite(rgb,sizeof(rgb),1,fp);

for(j=maxy-1;j>=0;j--){

for(i=0;i<maxx;i+=2){

mycolorcolorc2=color[getpixel(i,j)];

mycolorcolorc1=color[getpixel(i+1,j)];

putc(mycolorvalue,fp);

}

}

fclose(fp);

}

main()

{

int gd=DETECT,gm;

int maxx,maxy,key;

registerbgidriver(EGAVGA_driver); /用了这个函数后,你的程序就算在下面没指明BGI

路径也能在每台机器上运行,具体做法见我们论坛上贴子,<独立图形程序的建立>

>

registerbgidriver(EGAVGA_driver);

用这句你要先处理一些事才能用,详见我在论坛上的贴

独立图形程序的建立

>

以上就是关于C语言画图__并保存我画的图片全部的内容,包括:C语言画图__并保存我画的图片、如何用C语言软件画图、C语言画图程序运行一闪而过等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9823827.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存