网站首页 > 文章中心 > 其它

c语言中系统函数设定像素

作者:小编 更新时间:2023-08-22 19:23:28 浏览量:235人看过

putpixel和initgraph这样的函数在什么课里会学到?C语言程序设计?

putpixel

功 能: 在指定位置画一像素

用 法: void far putpixel (int x, int y, int pixelcolor);

initgraph

c语言中系统函数设定像素-图1

功 能: 初始化图形系统

函数原型: void far initgraph(int far *graphdriver, int far *graphmode,

我在C语言程序设计这本书没有见过这两个函数

当你想控制屏幕输出的内容的时候就会用到的

我需要c语言每个头文件里的所有函数介绍及用法!

分类函数,所在函数库为ctype.h

int isalpha(int ch) 若ch是字母('A'-'Z','a'-'z')返回非0值,否则返回0

返回非0值,否则返回0

int islower(int ch) 若ch是小写字母('a'-'z')返回非0值,否则返回0

int ispunct(int ch) 若ch是标点字符(0x00-0x1F)返回非0值,否则返回0

int isspace(int ch) 若ch是空格(' '),水平制表符('\t'),回车符('\r'),

走纸换行('\f'),垂直制表符('\v'),换行符('\n')

int isupper(int ch) 若ch是大写字母('A'-'Z')返回非0值,否则返回0

否则返回0

int tolower(int ch) 若ch是大写字母('A'-'Z')返回相应的小写字母('a'-'z')

int toupper(int ch) 若ch是小写字母('a'-'z')返回相应的大写字母('A'-'Z')

数学函数,所在函数库为math.h、stdlib.h、string.h、float.h

int abs(int i) 返回整型参数i的绝对值

double cabs(struct complex znum) 返回复数znum的绝对值

double fabs(double x) 返回双精度参数x的绝对值

long labs(long n) 返回长整型参数n的绝对值

double exp(double x) 返回指数函数ex的值

double log(double x) 返回logex的值

double log10(double x) 返回log10x的值

double pow(double x,double y) 返回xy的值

double pow10(int p) 返回10p的值

double sqrt(double x) 返回+√x的值

double acos(double x) 返回x的反余弦cos-1(x)值,x为弧度

double asin(double x) 返回x的反正弦sin-1(x)值,x为弧度

double atan(double x) 返回x的反正切tan-1(x)值,x为弧度

double cos(double x) 返回x的余弦cos(x)值,x为弧度

double sin(double x) 返回x的正弦sin(x)值,x为弧度

double tan(double x) 返回x的正切tan(x)值,x为弧度

double cosh(double x) 返回x的双曲余弦cosh(x)值,x为弧度

double sinh(double x) 返回x的双曲正弦sinh(x)值,x为弧度

double tanh(double x) 返回x的双曲正切tanh(x)值,x为弧度

double hypot(double x,double y) 返回直角三角形斜边的长度(z),

double ceil(double x) 返回不小于x的最小整数

double floor(double x) 返回不大于x的最大整数

void srand(unsigned seed) 初始化随机数发生器

int rand() 产生一个随机数并返回这个数

double poly(double x,int n,double c[])从参数产生一个多项式

double modf(double value,double *iptr)将双精度数value分解成尾数和阶

double fmod(double x,double y) 返回x/y的余数

double frexp(double value,int *eptr) 将双精度数value分成尾数和阶

double atof(char *nptr) 将字符串nptr转换成浮点数并返回这个浮点数

double atoi(char *nptr) 将字符串nptr转换成整数并返回这个整数

double atol(char *nptr) 将字符串nptr转换成长整数并返回这个整数

char *ecvt(double value,int ndigit,int *decpt,int *sign)

将浮点数value转换成字符串并返回该字符串

char *fcvt(double value,int ndigit,int *decpt,int *sign)

char *gcvt(double value,int ndigit,char *buf)

将数value转换成字符串并存于buf中,并返回buf的指针

char *ultoa(unsigned long value,char *string,int radix)

将无符号整型数value转换成字符串并返回该字符串,radix为转换时所用基数

char *ltoa(long value,char *string,int radix)

将长整型数value转换成字符串并返回该字符串,radix为转换时所用基数

char *itoa(int value,char *string,int radix)

将整数value转换成字符串存入string,radix为转换时所用基数

double atof(char *nptr) 将字符串nptr转换成双精度数,并返回这个数,错误返回0

int atoi(char *nptr) 将字符串nptr转换成整型数, 并返回这个数,错误返回0

long atol(char *nptr) 将字符串nptr转换成长整型数,并返回这个数,错误返回0

double strtod(char *str,char **endptr)将字符串str转换成双精度数,并返回这个数,

long strtol(char *str,char **endptr,int base)将字符串str转换成长整型数,

并返回这个数,

int matherr(struct exception *e)

用户修改数学错误返回信息函数(没有必要使用)

double _matherr(_mexcep why,char *fun,double *arg1p,

void _fpreset() 重新初使化浮点数学程序包

int chdir(char *path) 使指定的目录path(如:"C:\\WPS")变成当前的工作目录,成

功返回0

int findfirst(char *pathname,struct ffblk *ffblk,int attrib)查找指定的文件,成功

返回0

pathname为指定的目录名和文件名,如"C:\\WPS\\TXT"

ffblk为指定的保存文件信息的一个结构,定义如下:

┏━━━━━━━━━━━━━━━━━━━━┓

┃struct ffblk ┃

┃{ ┃

┃ char ff_attrib; /*文件属性*/ ┃

┃ int ff_ftime; /*文件时间*/ ┃

┃ int ff_fdate; /*文件日期*/ ┃

┃ long ff_fsize; /*文件长度*/ ┃

┃} ┃

┗━━━━━━━━━━━━━━━━━━━━━┛

attrib为文件属性,由以下字符代表

┏━━━━━━━━━┳━━━━━━━━━┓

┃FA_RDONLY 只读文件┃FA_LABEL 卷标号 ┃

┃FA_HIDDEN 隐藏文件┃FA_DIREC 目录 ┃

┃FA_SYSTEM 系统文件┃FA_ARCH 档案 ┃

┗━━━━━━━━━┻━━━━━━━━━┛

例:

struct ffblk ff;

findfirst("*.wps",ff,FA_RDONLY);

int findnext(struct ffblk *ffblk) 取匹配finddirst的文件,成功返回0

void fumerge(char *path,char *drive,char *dir,char *name,char *ext)

此函数通过盘符drive(C:、A:等),路径dir(\TC、\BC\LIB等),

文件名name(TC、WPS等),扩展名ext(.EXE、.COM等)组成一个文件名

存与path中.

int fnsplit(char *path,char *drive,char *dir,char *name,char *ext)

此函数将文件名path分解成盘符drive(C:、A:等),路径dir(\TC、\BC\LIB等),

文件名name(TC、WPS等),扩展名ext(.EXE、.COM等),并分别存入相应的变量中.

int getcurdir(int drive,char *direc) 此函数返回指定驱动器的当前工作目录名称

direc 保存指定驱动器当前工作路径的变量 成功返回0

char *getcwd(char *buf,iint n) 此函数取当前工作目录并存入buf中,直到n个字

节长为为止.错误返回NULL

返回可使用驱动器总数

int mkdir(char *pathname) 建立一个新的目录pathname,成功返回0

int rmdir(char *pathname) 删除一个目录pathname,成功返回0

char *mktemp(char *template) 构造一个当前目录上没有的文件名并存于template中

char *searchpath(char *pathname) 利用MSDOS找出文件filename所在路径,

,此函数使用DOS的PATH变量,未找到文件返回NULL

进程函数,所在函数库为stdlib.h、process.h

并异常终止程序.无返回值

int exec...装入和运行其它程序

int execl( char *pathname,char *arg0,char *arg1,...,char *argn,NULL)

int execle( char *pathname,char *arg0,char *arg1,...,

char *argn,NULL,char *envp[])

int execlp( char *pathname,char *arg0,char *arg1,...,NULL)

int execlpe(char *pathname,char *arg0,char *arg1,...,NULL,char *envp[])

int execv( char *pathname,char *argv[])

int execve( char *pathname,char *argv[],char *envp[])

int execvp( char *pathname,char *argv[])

int execvpe(char *pathname,char *argv[],char *envp[])

exec函数族装入并运行程序pathname,并将参数

在exec函数族中,后缀l、v、p、e添加到exec后,

所指定的函数将具有某种操作能力

有后缀 p时,函数可以利用DOS的PATH变量查找子程序文件.

l时,函数中被传递的参数个数固定.

v时,函数中被传递的参数个数不固定.

e时,函数传递指定参数envp,允许改变子进程的环境,

无后缀e时,子进程使用当前程序的环境.

void _exit(int status)终止当前程序,但不清理现场

void exit(int status) 终止当前程序,关闭所有文件,写缓冲区的输出(等待输出),

并调用任何寄存器的"出口函数",无返回值

int spawn...运行子程序

int spawnl( int mode,char *pathname,char *arg0,char *arg1,...,

char *argn,NULL)

int spawnle( int mode,char *pathname,char *arg0,char *arg1,...,

int spawnlp( int mode,char *pathname,char *arg0,char *arg1,...,

int spawnlpe(int mode,char *pathname,char *arg0,char *arg1,...,

int spawnv( int mode,char *pathname,char *argv[])

int spawnve( int mode,char *pathname,char *argv[],char *envp[])

int spawnvp( int mode,char *pathname,char *argv[])

int spawnvpe(int mode,char *pathname,char *argv[],char *envp[])

spawn函数族在mode模式下运行子程序pathname,并将参数

mode为运行模式

mode为 P_WAIT 表示在子程序运行完后返回本程序

P_NOWAIT 表示在子程序运行时同时运行本程序(不可用)

P_OVERLAY表示在本程序退出后运行子程序

在spawn函数族中,后缀l、v、p、e添加到spawn后,

有后缀 p时, 函数利用DOS的PATH查找子程序文件

l时, 函数传递的参数个数固定.

v时, 函数传递的参数个数不固定.

e时, 指定参数envp可以传递给子程序,允许改变子程序运行环境.

当无后缀e时,子程序使用本程序的环境.

int system(char *command) 将MSDOS命令command传递给DOS执行

转换子程序,函数库为math.h、stdlib.h、ctype.h、float.h

int toascii(int c) 返回c相应的ASCII

int tolower(int ch) 若ch是大写字母('A'-'Z')返回相应的小写字母('a'-'z')

int _tolower(int ch) 返回ch相应的小写字母('a'-'z')

int toupper(int ch) 若ch是小写字母('a'-'z')返回相应的大写字母('A'-'Z')

int _toupper(int ch) 返回ch相应的大写字母('A'-'Z')

诊断函数,所在函数库为assert.h、math.h

void assert(int test) 一个扩展成if语句那样的宏,如果test测试失败,

就显示一个信息并异常终止程序,无返回值

void perror(char *string) 本函数将显示最近一次的错误信息,格式如下:

字符串string:错误信息

char *strerror(char *str) 本函数返回最近一次的错误信息,格式如下:

字符串str:错误信息

int matherr(struct exception *e)

double _matherr(_mexcep why,char *fun,double *arg1p,

如何用c语言printf输出bmp图片的像素信息.

#includemath.h

#include?iomanip.h?

#include?stdlib.h

#include?windows.h

#include?stdio.h

#include?iostream.h

#include?fstream.h

//---------------------------------------------------------------------------------------

unsigned?char?*pBmpBuf;//读入图像数据的指针

int?bmpWidth;//图像的宽

int?bmpHeight;//图像的高

RGBQUAD?*pColorTable;//颜色表指针

int?biBitCount;//图像类型,每像素位数

//-------------------------------------------------------------------------------------------

//读图像的位图数据、宽、高、颜色表及每像素位数等数据进内存,存放在相应的全局变量中

bool?readBmp(char?*bmpName)?

{

FILE?*fp=fopen(bmpName,"rb");//二进制读方式打开指定的图像文件

if(fp==0)

return?0;

//跳过位图文件头结构BITMAPFILEHEADER

fseek(fp,?sizeof(BITMAPFILEHEADER),0);

//定义位图信息头结构变量,读取位图信息头进内存,存放在变量head中

BITMAPINFOHEADER?head;?

fread(head,?sizeof(BITMAPINFOHEADER),?1,fp);?//获取图像宽、高、每像素所占位数等信息

bmpWidth?=?head.biWidth;

bmpHeight?=?head.biHeight;

//申请颜色表所需要的空间,读颜色表进内存

}

//申请位图数据所需要的空间,读位图数据进内存

pBmpBuf=new?unsigned?char[lineByte?*?bmpHeight];

fread(pBmpBuf,1,lineByte?*?bmpHeight,fp);

fclose(fp);//关闭文件

return?1;//读取文件成功

//-----------------------------------------------------------------------------------------

//给定一个图像位图数据、宽、高、颜色表指针及每像素所占的位数等信息,将其写到指定文件中

bool?saveBmp(char?*bmpName,?unsigned?char?*imgBuf,?int?width,?int?height,?int?biBitCount,?RGBQUAD?*pColorTable)

//如果位图数据指针为0,则没有数据传入,函数返回

if(!imgBuf)

int?colorTablesize=0;

//以二进制写的方式打开文件

FILE?*fp=fopen(bmpName,"wb");

//申请位图文件头结构变量,填写文件头信息

BITMAPFILEHEADER?fileHead;

fileHead.bfSize=?sizeof(BITMAPFILEHEADER)?+?sizeof(BITMAPINFOHEADER)?+?colorTablesize?+?lineByte*height;

fileHead.bfReserved1?=?0;

//写文件头进文件

fwrite(fileHead,?sizeof(BITMAPFILEHEADER),1,?fp);

//申请位图信息头结构变量,填写信息头信息

head.biBitCount=biBitCount;

head.biClrImportant=0;

head.biClrUsed=0;

head.biCompression=0;

head.biHeight=height;

head.biPlanes=1;

head.biSizeImage=lineByte*height;

head.biWidth=width;

head.biXPelsPerMeter=0;

head.biYPelsPerMeter=0;

//写位图信息头进内存

fwrite(head,?sizeof(BITMAPINFOHEADER),1,?fp);

//如果灰度图像,有颜色表,写入文件?

//写位图数据进文件

fwrite(imgBuf,?height*lineByte,?1,?fp);

//关闭文件

fclose(fp);

return?1;

//----------------------------------------------------------------------------------------

//以下为像素的读取函数

void?doIt()

//读入指定BMP文件进内存

char?readPath[]="nv.BMP";

readBmp(readPath);

//输出图像的信息

cout"width="bmpWidth"?height="bmpHeight"?biBitCount="biBitCountendl;

//循环变量,图像的坐标

//每行字节数

//循环变量,针对彩色图像,遍历每像素的三个分量

int?m=0,n=0,count_xiang_su=0;

ofstream?outfile("图像像素.txt",ios::in|ios::trunc);

{???

//------------------------------------------------------------------------------------

//左下角:由左往右,由上往下逐行扫描的

int?L1=0;

int?lie=0;

{?

//--------------------------------------------

outfilem"?";

count_xiang_su++;

outfileendl;

//---------------------------------------------

//ofstream?outfile("xiang_su_zhi.txt",ios::in|ios::trunc);

if(!outfile)

cout"open?error!"endl;

exit(1);

{//彩色图像

for(int?i=0;ibmpHeight;i++)

for(int?j=0;jbmpWidth;j++)

//n++;

n++;

cout"总的像素个素为:"nendl;

cout"----------------------------------------------------"endl;

//将图像数据存盘

char?writePath[]="nvcpy.BMP";//图片处理后再存储

saveBmp(writePath,?pBmpBuf,?bmpWidth,?bmpHeight,?biBitCount,?pColorTable);

//清除缓冲区,pBmpBuf和pColorTable是全局变量,在文件读入时申请的空间

delete?[]pBmpBuf;

delete?[]pColorTable;

void?main()

doIt();

C/C++中显示像素点的函数

SetPixel

函数原型:COLORREF

SetPixel(HDC

hdc,

int

X,

Y,

COLORREF

crColor);

参数:

hdc:设备环境句柄.

X:指定要设置的点的X轴坐标,按逻辑单位表示坐标.

Y:指定要设置的点的Y轴坐标,按逻辑单位表示坐标.

crColor:指定要用来绘制该点的颜色.

头文件:wingdi.h:

如何利用c语言实现像素图形的输出

IplImage* img = cvLoadImage("test.bmp", 0);

for (int i = 0; i img-height; i++)

for (int j = 0; j img-width; j++)

printf("gray value=%f\n",s.val[0]);

//方法二:使用直接访问

uchar val = ((uchar *)(img-imageData + i*img-widthStep))[j];//i和j的意义同上

printf("gray value=%d\n",val);

IplImage* img = cvLoadImage("test.bmp", 1);

int bVal = ((uchar *)(img-imageData + i*img-widthStep))[j*img-nChannels + 0]; // B

int gVal = ((uchar *)(img-imageData + i*img-widthStep))[j*img-nChannels + 1]; // G

printf("B=%d, G=%d, R=%d\n",bVal,gVal,rVal);//注意是BGR顺序

以上就是土嘎嘎小编为大家整理的c语言中系统函数设定像素相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章