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

代码文件下载:点击打开链接




#include

#include
#include

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语言实现一个图片的读出和写入)