bool Compare(const char* aFile1,const char* aFile2,int x ,int y,int aWidth,int aHeight) { CxImage* aDecoder1 = new CxImage(); CxImage* aDecoder2 = new CxImage(); /**1.Open file*/ FILE* fp1 = fopen(aFile1,"rb"); if(NULL == fp1) { return OPEN_ERROR; } FILE* fp2 = fopen(aFile2,"rb"); if(NULL == fp1) { return OPEN_ERROR; } /**2.Decorder file */ if(!aDecoder1->Decode(fp1,CXIMAGE_SUPPORT_PNG)) { return DECODER_ERROR; } if(!aDecoder2->Decode(fp2,CXIMAGE_SUPPORT_PNG)) { return DECODER_ERROR; } /**3.Get buffer*/ BYTE *buf1= NULL; BYTE *buf2= NULL; int xCount = 0; int yCount = 0; int position = 0; int yChg = 0; buf1 = aDecoder1->GetBits(); buf2 = aDecoder2->GetBits(); int aPictureWidth = aDecoder1->GetWidth(); int aPictureHeight = aDecoder1->GetHeight(); if(aWidth !=0 && aPictureWidth != aWidth) { aPictureWidth = aWidth; } if(aHeight !=0 && aPictureHeight != aHeight) { aPictureHeight = aHeight; } if( x ) { xCount = x; } if(y) { yCount = aDecoder1->GetHeight() - (y + aHeight); } /**5.compare buffer*/ for(int tempy = yCount ; yCount < tempy + aHeight ; yCount++) { for(int tempx = xCount; xCount < tempx + aWidth ; xCount++) { position = xCount + yCount*aDecoder1->GetWidth(); int a = buf1[position]; int b = buf2[position]; if(buf1[position] != buf2[position]) { return IMAGE_DIFF; } } } return IMAGE_SAME; }
图片比较 C
最新推荐文章于 2021-05-28 17:42:53 发布