c语言打开图片的函数 c语言打开图片的源代码

c语言读取图片的函数是那些?

#include graphics.h

创新互联-专业网站定制、快速模板网站建设、高性价比镇远网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式镇远网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖镇远地区。费用合理售后完善,十余年实体公司更值得信赖。

int main()

{

int gdriver, gmode;

gdriver=VGA;

gmode=VGAHI;

initgraph(gdriver, gmode, "c:\\tc");

bar3d(100, 100, 300, 250, 50, 1); /*画一长方体*/

getch();

closegraph();

return 0;

}

有时编程者并不知道所用的图形显示器适配器种类, 或者需要将编写的程序 用于不同图形驱动器, Turbo C提供了一个自动检测显示器硬件的函数, 其调用

格式为:

void far detectgraph(int *gdriver, *gmode);

其中gdriver和gmode的意义与上面相同。

例5. 自动进行硬件测试后进行图形初始化

#include graphics.h

int main()

{

int gdriver, gmode;

detectgraph(gdriver, gmode); /*自动测试硬件*/

printf("the graphics driver is %d, mode is %d\n", gdriver, gmode); /*输出测试结果*/

getch();

initgraph(gdriver, gmode, "c:\\tc");

/* 根据测试结果初始化图形*/

bar3d(10, 10, 130, 250, 20, 1);

getch();

closegraph();

return 0;

}

上例程序中先对图形显示器自动检测, 然后再用图形初始化函数进行初始化设置, 但Turbo C提供了一种更简单的方法, 即用gdriver= DETECT 语句后再跟 initgraph()函数就行了。采用这种方法后, 上例可改为:

例6.

#include graphics.h

int main()

{

int gdriver=DETECT, gmode;

initgraph(gdriver, gmode, "c:\\tc");

bar3d(50, 50, 150, 30, 1);

getch();

closegraph();

return 0;

}

另外, Turbo C提供了退出图形状态的函数closegraph(), 其调用格式为:void far closegraph(void);调用该函数后可退出图形状态而进入文本方式(Turbo C 默认方式), 并释放用于保存图形驱动程序和字体的系统内存。

c语言调用图片函数

c语言调用图片函数

据我所知Matlab有,imshow(),c好象没有,c只能先将图片读到内存中,经过相关处理后以一定的格式保存到硬盘中,然后再打开图片.

读图和存图需要有专门的函数,这些可以参考:

unsigned

char*

ReadBMPData(int

Width,

int

Height,

char

*fname)//图像的宽和高,图像的位置(包括后缀)

{

unsigned

char*

image

=

new

unsigned

char[Width*Height];

FILE

*fp;

fp

=

fopen(fname,

"rb");

fread(image,

1,

Width*Height,

fp);

fclose(fp);

return

image;

}

///////////////////////////

void

WriteRawData(unsigned

char*

image,

int

Width,

int

Height,

char

*fname)

{

FILE

*fp;

fp

=

fopen(fname,

"wb");

fwrite(image,

1,

Width*Height,

fp);

fclose(fp);

}

如何用c语言读取图片

#include

using namespace std;

#define Twoto1(i,j,w) i*w+j

void createimage(unsigned char *img, int w, int h)

{img = new unsigned char[w*h];}

void delateimage(unsigned char*img)

{delete []img;}

void readimage(unsigned char*img, int w, int h, char *fname)

{

FILE *fp;

fopen_s(fp,fname, "rb");

if (fp == NULL){ cout "error" endl; return; }

size_t result;

result=fread(img , sizeof(unsigned char), w*h, fp);

if (result != w*h)

{

cout "Reading error" endl;

return;

}

else

cout "Reading Ok!" endl;

fclose(fp);

}

void mobanjuanji(unsigned char image, unsigned char*image1, int w, int h, float moban[5][5])

{

for (int i = 0; i for (int j = 0; j if (iw - 3 || jh - 3)

image1[Twoto1(i,j,w)] = 0;

else

{

float temp = 0;

for (int m = 0; m5; m++)

for (int n = 0; n5; n++)

{

temp += (image[Twoto1(i-2+m,j-2+n,w)] moban[m][n]);

}

if (temp255) image1[Twoto1(i, j, w)] = 255;

else if (temp0) image1[Twoto1(i, j, w)] = 0;

else image1[Twoto1(i, j, w)] = temp;

}

}

void saveimage(unsigned char *img, int w, int h, char *fname)

{

FILE *fp;

fopen_s(fp, fname, "wb");

if (fp == NULL) { cout "error" endl; return; }

size_t result;

result = fwrite(img, sizeof(unsigned char), w*h, fp);

if (result != w*h)

{

cout "Write error" endl;

return;

}

else

cout "Write Ok!" endl;

fclose(fp);

}

void main()

{

unsigned char *img;

unsigned char *img1;

float moban[5][5] = { {0,0,0,0,0},{0, -1, 0, 1, 0 }, { 0, -2, 0, 2, 0 }, { 0, -1, 0, 1, 0 }, { 0,0,0,0,0 } };

//float moban[5][5] = { 0 };

int w = 512, h = 512;

createimage(img, w, h);

createimage(img1, w, h);

readimage(img, w, h, "E:\ss.raw");

mobanjuanji(img, img1,w, h, moban);

saveimage(img, w, h, "E:\ss_1.raw");

saveimage(img1, w, h, "E:\ss_2.raw");

delateimage(img);

delateimage(img1);

}

扩展资料

C语言实现一个图片的读出和写入

#include stdlib.h

#include windows.h

int file_size(char* filename)//获取文件名为filename的文件大小。

{

FILE *fp = fopen(filename, "rb");//打开文件。

int size;

if(fp == NULL) // 打开文件失败

return -1;

fseek(fp, 0, SEEK_END);//定位文件指针到文件尾。

size=ftell(fp);//获取文件指针偏移量,即文件大小。

fclose(fp);//关闭文件。

return size;

}

int main ()

{

int size=0;

size=file_size("qw");

printf("%d\n",size);

FILE * pFile,*qw;

char *buffer=(char*)malloc(sizeof(char)*size);

qw   =fopen("qw","r");

pFile = fopen ( "qwe" , "wb" );

printf("%d==\n",pFile);

printf("%d\n",size);

fread(buffer,1,size,qw);

fwrite (buffer , sizeof(byte), size , pFile );

fclose (pFile);

rename("qwe","Groot.jpg");

return 0;

}


分享名称:c语言打开图片的函数 c语言打开图片的源代码
网页URL:http://scyanting.com/article/dopihpe.html