導航:首頁 > 動漫圖片 > c怎麼讀取圖片

c怎麼讀取圖片

發布時間:2023-06-06 05:03:36

㈠ c語言如何調用圖片

直接調用並顯示JPG BMP等格式圖片的函數好像沒有,要自己編寫。
首先要弄清楚圖片格式的編碼方式,然後設置解析度,可以顯示出來。
void far getimage(int left,int top,int right,int bottom,void far *buf)
說明:把屏幕圖形部分拷貝到由BUF所指向的內在區域,左上角和右下角圖標。用函數IMAGESIZE()來確定存儲圖像所需位元組數。用GETIMAGE()存儲的圖像可以用PUTIMAGTE()函數寫到屏幕上。

㈡ 用c語言如何讀取和保存jpg圖片文件

#include <stdio.h>

#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;

}

(2)c怎麼讀取圖片擴展閱讀:

c語言讀取TXT文件:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#define MAX_LINE 1024

int main()

{

char buf[MAX_LINE]; /*緩沖區*/

FILE *fp; /*文件指針*/

int len; /*行字元個數*/

if((fp = fopen("test.txt","r")) == NULL)

{

perror("fail to read");

exit (1) ;

}

while(fgets(buf,MAX_LINE,fp) != NULL)

{

len = strlen(buf);

buf[len-1] = ''; /*去掉換行符*/

printf("%s %d ",buf,len - 1);

}

return 0;

}




㈢ 如何用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);

}

(3)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怎麼讀取圖片相關的資料

熱點內容
十個女孩子的卡通圖片 瀏覽:377
外表憨憨的男生圖片 瀏覽:785
小孩圖片頭像可愛萌 瀏覽:464
全世界安靜的圖片大全 瀏覽:581
四清明節手抄報圖片簡單 瀏覽:893
情侶壁紙圖片高清可愛一對 瀏覽:912
給女生看風景圖片要說什麼 瀏覽:257
不給糖就搗蛋粉紅可愛圖片 瀏覽:350
普通女孩生活照片圖片 瀏覽:782
初中生的圖片唯美高清壁紙 瀏覽:778
簡單的酒櫃圖片 瀏覽:692
餘生請多指導文字圖片 瀏覽:317
word文檔圖片怎麼調順序 瀏覽:578
卡通照片衣服設計圖片 瀏覽:126
小學生手工簡單又漂亮的圖片 瀏覽:731
美女奶機大全圖片 瀏覽:525
簡單的春節畫手抄報圖片 瀏覽:994
手機點不開圖片怎麼辦 瀏覽:883
word里的背景圖片怎麼去掉 瀏覽:548
pr如何兩個圖片同步 瀏覽:81