求助,用C语言读取bmp图像并显示,显示结果如下一般是出现了什么问题呀
求助bmp图像的识别
122 views
求助,用C语言读取bmp图像并显示,显示结果如下一般是出现了什么问题呀
排查后感觉是读取数据的问题
void getData1(FILE* fp, Point** Pix, long height, long width, int offset)
{
FILE* fpr;
errno_t err_pr;
FILE* fpg;
errno_t err_pg;
FILE* fpb;
errno_t err_pb;
int i, j = 0;
int stride;
unsigned char* pix = NULL;
fseek(fp, offset, SEEK_SET); //找到位图的数据区
stride = (24 * width + 31) / 8; //对齐,计算一行有多少个8位
stride = stride / 4 * 4; //取四的倍数 r,g,b,alph
//写入数组
pix = (unsigned char*)malloc(stride);
for (j = 0; j < height; j++)
{
fread(pix, 1, stride, fp);
for (i = 0; i < width; i++)
{
Pix[height - j - 1][i].r = pix[i * 3 + 2];
Pix[height - j - 1][i].g = pix[i * 3 + 1];
Pix[height - j - 1][i].b = pix[i * 3];
}
}
err_pr = fopen_s(&fpr, "bmpr1.txt", "w+");
err_pg = fopen_s(&fpg, "bmpg1.txt", "w+");
err_pb = fopen_s(&fpb, "bmpb1.txt", "w+");
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
fprintf(fpr, "%4d", Pix[i][j].r);
fprintf(fpg, "%4d", Pix[i][j].g);
fprintf(fpb, "%4d", Pix[i][j].b);
}
//fprintf(fpr, "\n");
//fprintf(fpg, "\n");
//fprintf(fpb, "\n");
}
}