我想以二进制形式将数据写入文件.
我正在尝试使用下面提到的
FILE *fp = fopen("binaryoutput.rgb888", "ab+");
for(int m=0; m<height; m++)
{
for (int n=0; n< width; n++)
{
temp = (pOutputImg+m*3+n*3); // here pOutputImg & temp is a pointer to a unsigned char
fprintf(fp,"%u",*temp);
}
}
fclose(fp);
Run Code Online (Sandbox Code Playgroud)
我能够获得以pOutputImg而非二进制形式的数据.
任何人都可以指导我正确的步骤..
提前致谢
用fwrite()替换fprintf().
例如:
fwrite(temp, sizeof(*temp), 1, fp);
Run Code Online (Sandbox Code Playgroud)
fprintf()的全部目的是将二进制数据格式化为可读的ascii ...与您想要的完全相反.fwrite()用于直接写入二进制数据.