我觉得,比较图片直接比较图片的二进制码就可以了。因为如果二进制码改变了,这个图片一定会改变的。不过改变的是什么我们就不用管了。比如画质什么的。 也可以用像素比较。不过。。。。。。。唉,一直没思路
不能使用Unicode字节集!因为我没用这个,否则char*转换LPCSTR可能会很麻烦
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
#define Size 300 //字符串长度(动态数组有点不方便了)
#define JpgSize 50000 //图片长度
#define Message(Text) MessageBox(NULL,(LPCSTR)Text,(LPCSTR)" ",MB_OK)
#define pause() system("pause")
int main(void)
{
BOOL tf;
FILE *JpgFile;
FILE *AJpgFile;
unsigned char PicByte[JpgSize]={0};//初始化
unsigned char APicByte[JpgSize]={0};//初始化
char Picname[Size];
char APicname[Size];
tf=SetConsoleTitle((LPCSTR)"图片比较软件 By:紫玫冰心");//修改标题
if(tf==FALSE)//标题修改失败
{
Message("软件初始化失败!");
return 0;
}
/* 第一个图片 */
printf("要匹配的文件名:");
scanf("%s",Picname);
/* 另一个图片 */
printf("被匹配的文件名:");
scanf("%s",APicname);
JpgFile=fopen(Picname,"rb+");
if(!JpgFile)
puts("打开文件失败!");
else if(!feof(JpgFile))
{
fread(PicByte,1,JpgSize,JpgFile);
fclose(JpgFile);
AJpgFile=fopen(APicname,"rb+");
if(!AJpgFile)
puts("打开文件失败!");
else if(!feof(AJpgFile))
{
fread(APicByte,1,JpgSize,AJpgFile);
if(memcmp((void*)PicByte,(void*)APicByte,JpgSize)==0)
puts("两张图片相等!");
else
puts("两张图片不相等!");
fclose(AJpgFile);
}
}
pause();
return 0;
}