C 讀取bmp內容

2021-07-07 03:07:41 字數 1074 閱讀 4669

最近在寫b站的彈幕,首先碰到的就是如何將顯示。

後來發現b站彈幕底層用的是flash的bitmap來將影象顯示。大致的流程是

輸入一串base64加密的字串->extract取出所有的pixel->bitmap.setpixel進行顯示

這裡直接貼出**

function extract(data) 

outputbuffer[0] = (databuffer[0] << 2) + ((databuffer[1] & 0x30) >> 4);

outputbuffer[1] = ((databuffer[1] & 0x0f) << 4) + ((databuffer[2] & 0x3c) >> 2);

outputbuffer[2] = ((databuffer[2] & 0x03) << 6) + databuffer[3];

for (var k = 0; k < outputbuffer.length; k++)

}output.position = 0;

return output;

}

上述**用來將base64字串生成乙個所有影象資料的一維陣列。

int main(int argc, const char * argv)

int num[4], cnt = 0, thresh = 0;

int temp, width_cnt = 0;

long length = long_max - 54;

char buf[10] = "";

long width = 0, height = 0;

while (!in.eof() && cnt < length + 54)

if (thresh == 255 * 3) else

for (int i = 0; i < 4; i++) {

sprintf(buf, "%02x", num[i]);

ss<

bmp的格式在18位元組處儲存了寬高的資訊,從第54位元組處是所有實際的影象資料。

需要注意的是bmp是4位元組對齊的,所以遇到不是4位元組對齊的長寬需要額外處理。

c語言讀取bmp檔案

一 了解bmp檔案的格式 位 件頭 位圖資訊段 調色盤資訊 一般都沒有 位圖資料,各部分關鍵字段。詳細資訊參見 讀取bmp檔案的函式所需要的標頭檔案 include include include include include bmpstru.h define malloc type,n type...

BMP檔案的讀取

執行測試效果 void cmyview onreadbmp if strfilepath file fp fopen strfilepath,r bitmapfileheader fileheader bitmapinfo info fread fileheader,sizeof fileheade...

讀取BMP格式資料

pragma once include class digitalimage 還需要計算顏色表的位元組長度啊,用於定位畫素位置,難道不是顏色數嗎?no.dword rgblen size sizeof rgbquad 我還以為是這樣,size 4 畫素資料指標,怎麼計算 m lpbmpdata m ...