建立8位DIB並顯示

2021-05-23 02:46:07 字數 1549 閱讀 2522

做的乙個專案由於系統是8位的,對於24位的dib點陣圖使用bitblt函式的時候非常慢,在debug下測試對於2500*2500的影象,bitblt函式用了大概4000-5000ms,非常的受不了,這裡主要是由於系統是8位的,你建立的是24位的dib,這時候用bitblt函式的時候系統會做很多轉換工作,所以速度就非常慢,解決辦法就是直接建立8位的dib來顯示,和顯示24位dib最大的不同就是要把調色盤資訊加到位**件頭中:

lpbyte lpbitmapinfo = null;

bitmapinfoheader *lpbitmapheader;

rgbquad *lprgb;

int i;

lpbitmapinfo = (lpbyte)new char[sizeof(bitmapinfoheader) + 256 * sizeof(rgbquad) ];

if (lpbitmapinfo == null) 

return;

lpbitmapheader = (bitmapinfoheader *)lpbitmapinfo;

lpbitmapheader->bisize = sizeof (bitmapinfoheader) ;

lpbitmapheader->biwidth = wnd_w ;

lpbitmapheader->biheight = -wnd_h ;

lpbitmapheader->biplanes = 1 ;

lpbitmapheader->bibitcount = 8 ;

lpbitmapheader->bicompression = bi_rgb ;

lpbitmapheader->bisizeimage = wnd_w * wnd_h;

lpbitmapheader->bixpelspermeter = 0 ;

lpbitmapheader->biypelspermeter = 0 ;

lpbitmapheader->biclrused = 0 ;

lpbitmapheader->biclrimportant = 0 ;

關於調色盤的地方不用自己再去設定系統調色盤,要直接再建立點陣圖的時候加上去

lprgb = (rgbquad *)(lpbitmapinfo + sizeof(bitmapinfoheader));

for (i = 0; i < 256; i++)

hbitmap=createdibsection(dc.getsafehdc(),

(const bitmapinfo *)lpbitmapinfo,

dib_rgb_colors, 

//dib_pal_colors,

(void **)&rev_buff, 

null,

0);

memcpy(rev_buff, g_ptempbuff, wnd_w*wnd_h);//g_ptempbuff中存放的是8位灰度值。

dc.bitblt(0, 0, wnd_w, wnd_h, &dccompatible, 0, 0, srccopy);

ok,這樣bitblt的時間在debug下不超過500ms了。

建立8位DIB並顯示

做的乙個專案由於系統是8位的,對於24位的dib點陣圖使用bitblt函式的時候非常慢,在debug下測試對於2500 2500的影象,bitblt函式用了大概4000 5000ms,非常的受不了,這裡主要是由於系統是8位的,你建立的是24位的dib,這時候用bitblt函式的時候系統會做很多轉換工...

VC 建立BMP檔案並顯示

建立mfc cstatic的pciture外掛程式 設定為frame 1 在標頭檔案中初始化bmp檔案頭資訊變數 bitmapfileheaderm bmfheader bitmapinfoheaderm bmiheader lpbyte lpbbmdata bitmapinfo bminfo ui...

動態建立button並顯示選單

我的form上有3個panel,我要在指定的panel上動態建立多個button,請問各位,這 如何寫?點這個button時要能彈出選單 var btn1 tbutton begin btn1 tbutton.create owner btn1.parent panel1 end var butto...