當前位置:編程學習大全網 - 編程軟體 - 用c語言如何讀取和保存jpg圖片文件?

用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\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語言讀取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] = '\0';? /*去掉換行符*/

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

}

return 0;

}

  • 上一篇:協林變頻器sf100工作參數
  • 下一篇:北大青鳥Java培訓:程序員應該如何提升自己?
  • copyright 2024編程學習大全網