作者s4399 (小鬼)
看板C_and_CPP
标题[问题] 请问bmp图档
时间Tue May 5 17:32:46 2009
小弟想请问如何每次只读取bmp档里的一个bit
以下是我读档的程式码 可是应该只是把test.bmp复制过去test_bit.bmp而已
我该怎麽修改 谢谢!
ttt = 0;
row1 = width*3;(考虑RGB)
col1 = heigh;
if( ( rfp = fopen("test.bmp", "rb")) == NULL ||
( wfp = fopen("test_bit.bmp", "wb")) == NULL )
{
printf("Can not open file(s)! ");
return 0;
}
fread ( title, sizeof(char), 54, rfp );
fwrite( title, sizeof(char), 54, wfp );
fread( img, sizeof(char), heigh*width*3, rfp );
for( i = 0; i < heigh*width*3; i++ )
img1[i] = img[i];
fwrite( img1, sizeof(char), heigh*width*3, wfp );
fclose(wfp);
fclose(rfp);
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.135.8.248
1F:→ s4399:我有爬文 但还是看不太懂 05/05 17:45
2F:→ jerohands:一个bit还是一个pixel? 05/05 18:19
3F:→ jerohands:现有的函式库OpenCV,两三行就可以做完你要做的事 05/05 18:20
4F:→ jerohands:Google一下吧 05/05 18:21
5F:→ jiansu:bit有点不合理,你要的话读出以後存在记忆体,算出位置就可以 05/05 20:13
6F:→ jiansu:BTW 我记得bmp 会有padding这个动作,程式好像没考虑 05/05 20:15