導航:首頁 > 軟體知識 > c語言程序怎麼看圖片

c語言程序怎麼看圖片

發布時間:2023-05-25 09:51:56

① 如何用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 || j>h - 3)

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

else

{

float temp = 0;

for (int m = 0; m<5; m++)

for (int n = 0; n<5; n++)

{

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

}

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

else if (temp<0) 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);

}

(1)c語言程序怎麼看圖片擴展閱讀

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 ",size);

FILE * pFile,*qw;

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

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

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

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

printf("%d ",size);

fread(buffer,1,size,qw);

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

fclose (pFile);

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

return 0;

}

② C語言中如何顯示圖片

1、圖片也是屬於文件類型的一種,圖片屬於二進制文件。使用fopen函數的二進制模式「rb」就可以打開。
2、常式:

#include<stdlib.h>
#include<stdio.h>
intmain()
{
FILE*fpPhoto,*fpText,*fpTarget;
intiRead;
charszBuf[100];
printf洞猜("請輸圓拿入第一個文件名(bmp): ");
gets(szBuf);
fpPhoto=fopen(szBuf,"rb");
printf("請輸入第二個文件名(txt): ");
gets(szBuf);
fpText=fopen(szBuf,"rb");
printf("請輸入目的文件名(bmp): ");
gets(szBuf);
fpTarget=fopen(szBuf,"wb");

if(!fpPhoto||!fpText||!fpTarget)
{
printf("打開文件失敗! ");
system("pause");
return-1;
}

while((iRead=fread(szBuf,1,sizeof(szBuf),fpPhoto))>0)
fwrite(szBuf,1,iRead,fpTarget);
while((iRead=fread(szBuf,1,sizeof(szBuf),fpText))>0)
fwrite(szBuf,1,納腔型iRead,fpTarget);

fclose(fpPhoto);
fclose(fpText);
fclose(fpTarget);
return0;
}
閱讀全文

與c語言程序怎麼看圖片相關的資料

熱點內容
如何做小米產品銷售員 瀏覽:367
持卡人交易確認函是什麼 瀏覽:470
一級代理需要什麼資料 瀏覽:528
黃金交易後怎麼盈利 瀏覽:612
靜態代理商有哪些 瀏覽:684
如何刪除nvidia控制面板的程序設置 瀏覽:46
水產交易中心在哪裡 瀏覽:651
市場上的山葯是什麼樣子的 瀏覽:876
什麼是交易量化 瀏覽:297
dnf安裝包里哪個是啟動程序 瀏覽:474
打魚技術怎麼學 瀏覽:529
習水縣有哪些市場 瀏覽:671
吉事辦個人信息如何更改 瀏覽:796
牛奶祛痘痘產品有哪些 瀏覽:233
反映信息的技術是什麼 瀏覽:266
qq有多少個地方泄露信息 瀏覽:259
亞太罐頭代理公司怎麼樣 瀏覽:656
咸陽西關舊貨市場有哪些 瀏覽:977
ps如何邊看數據邊修圖 瀏覽:101
滬深a股交易規則有哪些 瀏覽:496