在研究dlp投影仪时,由于想要投影1位深的位图图像,在知乎上找到一段代码:
openCV将8bit(1像素对应8bit)图像保存为1bit(1像素对应1bit) - 知乎
在运行到此段代码时,报错:VC Critical error detected c0000374;
std::ofstream fp(dst.c_str(), std::ios::binary | std::ios::out);
在看了几篇文章后,调试了好久,终于发现了问题!
VC Critical error detected c0000374 崩溃问题及解决_恋恋西风的博客-CSDN博客_c0000374
在save1BitImage函数中,有如下代码:
int line_byte = (width * biBitCount >> 3 + 3) / 4 * 4;
char* p_data = (char*)malloc(line_byte * height);
此处右移操作符优先级小于加号运算符,因此这里相当于右移了6位。本来是为了计算4字节一像素值的行像素字节长度才要右移3位(除以8)。直接导致分配动态内存长度错误!
所以改为
//待存储图像数据每行字节数为4的倍数
int line_byte = ((width * biBitCount >> 3 ) + 3) / 4 * 4;
调试通过。