我有两个 .bmp 图像,每个都有 661 字节的标题。我被跳过了标题。
跳过标题后,我尝试将两个图像与以下代码进行比较。但它不起作用。
是否有任何逻辑错误在这段代码中,我试图弄清楚发生了什么,但我失败了。谁能帮我弄清楚发生了什么?
#include <stdio.h>
typedef struct {
char R,G,B;
} colorRGB;
colorRGB *RGB_buffer1, *RGB_buffer2;
void main() {
unsigned char tmpBuf1[651],tmpBuf2[651];
int i=0;
int nrline;
FILE *Img1 = fopen("sample.bmp","r");
FILE *Img2 = fopen("sample2.bmp","r");
int height = 256;
int width = 256;
fread ( tmpBuf1, 1, 651, Img1 );
fread ( tmpBuf2, 1, 651, Img2 );
RGB_buffer1 = (colorRGB *) malloc (3 * width * height) ;
RGB_buffer2 = (colorRGB *) malloc (3 * width * height) ;
for ( nrline = 0; nrline < height; nrline++ ) {
fread( RGB_buffer1 + nrline * width, 1, width * 3, Img1 );
fread( RGB_buffer2 + nrline * width, 1, width * 3, Img2 );
}
fclose (Img1);
fclose (Img2);
for( i = 0; i < height; i++ )
if( (RGB_buffer1[i].R != RGB_buffer2[i].R) &&
(RGB_buffer1[i].G != RGB_buffer2[i].G) &&
(RGB_buffer1[i].B != RGB_buffer2[i].B) ) break;
if ( i == height )
printf ( "Images are same\n" );
free (RGB_buffer1);
free (RGB_buffer2);
}