我有一个问题,一些失败的方式,我不明白。
在这段代码中,fwrite失败并给出tmp = 0。
if ((file = fopen(filenameout, "wb")) != NULL)
{
bmpheader->filesz += bmpdib->bmp_bytesz;
bmpdib->bmp_bytesz *= 2;
bmpdib->height *= 2;
tmp = fwrite(bmpheader, sizeof(bmp_header_t), 1, file);
tmp = fwrite(bmpdib, sizeof(bmp_dib_t), 1, file);
tmp = fwrite(bmpdata1, bmpdib->bmp_bytesz, 1, file);
tmp = fwrite(bmpdata2, bmpdib->bmp_bytesz, 1, file);
fclose(file);
}
else
return 1;但是,如果我评论一行代码,一切都很好:
if ((file = fopen(filenameout, "wb")) != NULL)
{
bmpheader->filesz += bmpdib->bmp_bytesz;
// bmpdib->bmp_bytesz *= 2;
bmpdib->height *= 2;
tmp = fwrite(bmpheader, sizeof(bmp_header_t), 1, file);
tmp = fwrite(bmpdib, sizeof(bmp_dib_t), 1, file);
tmp = fwrite(bmpdata1, bmpdib->bmp_bytesz, 1, file);
tmp = fwrite(bmpdata2, bmpdib->bmp_bytesz, 1, file);
fclose(file);
}
else
return 1;我仔细检查了代码中的每一个细节:
我的代码的目标是编写一个图像,并修改它的副本,以获得比原始图像高两倍的最终图像。原始位图是570 x 363 x 24位bmp图像。
我做错了什么?
任何帮助都是非常感谢的,谢谢。
发布于 2014-11-13 12:00:57
这解决了问题。多亏了艺术。
if ((file = fopen(filenameout, "wb")) != NULL)
{
bmpheader->filesz += bmpdib->bmp_bytesz;
bmpdib->bmp_bytesz *= 2;
bmpdib->height *= 2;
tmp = fwrite(bmpheader, sizeof(bmp_header_t), 1, file);
tmp = fwrite(bmpdib, sizeof(bmp_dib_t), 1, file);
tmp = fwrite(bmpdata1, bmpdib->bmp_bytesz / 2, 1, file);
tmp = fwrite(bmpdata2, bmpdib->bmp_bytesz / 2, 1, file);
fclose(file);
}
else
return 1;我错误地使用了更新后的位图数据大小来写入最终图像的每个部分。结果图像的高度是原来的两倍,因为它是由两个叠加的图像组成的,每个图像被写在一个单独的'fwrite‘操作中,每个操作的结果是位图数据大小的一半。
https://stackoverflow.com/questions/26908086
复制相似问题