我试图将一个 bmp 图像克隆到另一个 bmp 图像中,但最终图像无法打开。
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <process.h>
void readBMP(char* filename) {
int i;
FILE* f = fopen(filename, "rb");
FILE* f1= fopen("save.bmp", "wb");
if (!f) {
printf("Could not read file!\n");
exit(0);
}
unsigned char info[54];
fread(info, sizeof(unsigned char), 54, f);
int width = *(int*)&info[18];
int height = *(int*)&info[22];
printf("%d %d\n", width, height);
fwrite(info, sizeof(unsigned char), 54, f1);
int length = width * height;
unsigned int image[10000][3];
for(i = 0; i < length; i++) {
image[i][2] = getc(f);
image[i][1] = getc(f);
image[i][0] = getc(f);
putc(image[i][2], f1);
putc(image[i][1], f1);
putc(image[i][0], f1);
printf("pixel %d : [%d,%d,%d]\n", i+1, image[i][0], image[i][1], image[i][2]);
}
fclose(f);
fclose(f1);
}
void main() {
char* fileName = "bitgray.bmp";
readBMP(fileName);
getch();
}
我作为输入的图像是 114X81,大小为 27918 字节。最终图像的大小相同,但大小为 27756 字节。
可能是什么错误?