展开全部
程序代码(c++版):
#include<iostream.h>
#include<stdio.h>
void main()
{
char filename[50];
unsigned char oi[128][128];
unsigned char ii[128][128];
int Row=128,Col=128;//定义长和宽
cout<<"请输入要打开的文件:"<<endl;
cin>>filename;
FILE *fp;
if((fp=fopen(filename,"rb"))==0)//输入要打开的文件
{
cout<<"Cannot open file,push any key!"<<endl;//如果不可打开,报错
getchar();
return;
}
fseek(fp,1078L,0);//
fread(ii,1,128*128,fp);
fclose(fp);
for(int k=0;k<Row;k++)
for(int j=0;j<Col;j++)
{
oi[k][j]=ii[Row-k-1][j];//转换坐标。若起初i=127,转化后row-127-1=128-127-1=0
cout<<(int)oi[k][j]<<" ";
if((k*Row+j)%10==0)
cout<<endl;
}
cout<<endl;
cout<<"********************************************************************************"<<endl;
FILE *fp1;
cout<<"请输入要打开的文件:"<<endl;
cin>>filename;
if((fp1=fopen(filename,"wb"))==0)//输入要打开的文件
{
cout<<"Cannot open file"<<endl;//如果不可打开,报错
getchar();
return;
}
fwrite(oi,1,128*128,fp1);
fclose(fp1);
cout<<endl;
cout<<"********************************************************************************"<<endl;
cout<<"文件已保存,感谢使用!"<<endl;
}
c语言版:
#include <stdio.h>
#include<stdlib.h>
static unsigned char ii[128][128];
int Row=128,Col=128;
char file_name[40];
Load_data_file()
{
int f1;
int i,n;
unsigned long offbits;
FILE *fp;
printf("Please input original file name :");
scanf("%s",file_name);
f1=Col*Row;
if((fp=fopen(file_name,"rb"))==0)
{
printf("Cannot open file,push any key!\n");
putchar(0x07);
getchar();
exit(0);
}
fseek(fp,10L,0);
fread(&offbits,4,1,fp);
printf("offBits=%ld\n",offbits);
printf("press any key to continue\n");
putchar(0x07);
getchar();
fseek(fp,offbits,0);
if(fread(ii,1,f1,fp)!=f1)
{
printf("File read error\n");
putchar(0x07);
getchar();
exit(0);
}
fclose(fp);
};
void main()
{ FILE * fp;
unsigned char oi[128][128];
int f2=Col*Row,i,j;
Load_data_file();
for(i=0;i<Row;i++)
for(j=0;j<Col;j++)
{
oi[i][j]=ii[Row-i-1][j];
printf("%d ",oi[i][j]);
}
printf("\n");
printf("Input save file name:");
scanf("%s",file_name);
if((fp=fopen(file_name,"wb"))==0)
{
printf("Cannot open file\n");
return;
}
if(fwrite(oi,1,f2,fp)!=f2)
printf("File write error\n");
fclose(fp);
getchar();
return;
}
注意:bmp格式的图像应为8位,老师应该会提供。
#include<iostream.h>
#include<stdio.h>
void main()
{
char filename[50];
unsigned char oi[128][128];
unsigned char ii[128][128];
int Row=128,Col=128;//定义长和宽
cout<<"请输入要打开的文件:"<<endl;
cin>>filename;
FILE *fp;
if((fp=fopen(filename,"rb"))==0)//输入要打开的文件
{
cout<<"Cannot open file,push any key!"<<endl;//如果不可打开,报错
getchar();
return;
}
fseek(fp,1078L,0);//
fread(ii,1,128*128,fp);
fclose(fp);
for(int k=0;k<Row;k++)
for(int j=0;j<Col;j++)
{
oi[k][j]=ii[Row-k-1][j];//转换坐标。若起初i=127,转化后row-127-1=128-127-1=0
cout<<(int)oi[k][j]<<" ";
if((k*Row+j)%10==0)
cout<<endl;
}
cout<<endl;
cout<<"********************************************************************************"<<endl;
FILE *fp1;
cout<<"请输入要打开的文件:"<<endl;
cin>>filename;
if((fp1=fopen(filename,"wb"))==0)//输入要打开的文件
{
cout<<"Cannot open file"<<endl;//如果不可打开,报错
getchar();
return;
}
fwrite(oi,1,128*128,fp1);
fclose(fp1);
cout<<endl;
cout<<"********************************************************************************"<<endl;
cout<<"文件已保存,感谢使用!"<<endl;
}
c语言版:
#include <stdio.h>
#include<stdlib.h>
static unsigned char ii[128][128];
int Row=128,Col=128;
char file_name[40];
Load_data_file()
{
int f1;
int i,n;
unsigned long offbits;
FILE *fp;
printf("Please input original file name :");
scanf("%s",file_name);
f1=Col*Row;
if((fp=fopen(file_name,"rb"))==0)
{
printf("Cannot open file,push any key!\n");
putchar(0x07);
getchar();
exit(0);
}
fseek(fp,10L,0);
fread(&offbits,4,1,fp);
printf("offBits=%ld\n",offbits);
printf("press any key to continue\n");
putchar(0x07);
getchar();
fseek(fp,offbits,0);
if(fread(ii,1,f1,fp)!=f1)
{
printf("File read error\n");
putchar(0x07);
getchar();
exit(0);
}
fclose(fp);
};
void main()
{ FILE * fp;
unsigned char oi[128][128];
int f2=Col*Row,i,j;
Load_data_file();
for(i=0;i<Row;i++)
for(j=0;j<Col;j++)
{
oi[i][j]=ii[Row-i-1][j];
printf("%d ",oi[i][j]);
}
printf("\n");
printf("Input save file name:");
scanf("%s",file_name);
if((fp=fopen(file_name,"wb"))==0)
{
printf("Cannot open file\n");
return;
}
if(fwrite(oi,1,f2,fp)!=f2)
printf("File write error\n");
fclose(fp);
getchar();
return;
}
注意:bmp格式的图像应为8位,老师应该会提供。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |