【发布时间】:2013-10-10 14:44:11
【问题描述】:
我有两个 .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);
}
【问题讨论】:
-
你到底想问什么?
-
与其忽略标题,不如用它来确定高度、宽度、颜色深度、托盘等。在检查一些第一个字节之前,您甚至不知道标题的大小。 en.wikipedia.org/wiki/BMP_file_format
-
快速检查,文件大小是否正好为 197259 字节?还有
sizeof(colorRGB)是什么?
标签: c algorithm image-processing