[問題] 抓取某個視窗的畫面

看板C_and_CPP (C/C++)作者 (不下棋)時間11年前 (2014/06/27 20:17), 編輯推噓0(005)
留言5則, 4人參與, 最新討論串1/1
平台VC++ 2010 Win7 32bit 我想抓取某個視窗的畫面 在網路上看到這段程式說可以用 想問一下 1.為什麼它用的陣列大小是width*height*4(要乘以四呢?) 2.這樣抓到的bitmap位元數是16bit的嗎? ::GetWindowRect(hwndAbout,&aRect); int width = aRect.bottom; int height = aRect.right; HDC hdc; hdc=::GetDC(hwndAbout); HDC memDC = ::CreateCompatibleDC (hdc); HBITMAP bitmap = ::CreateCompatibleBitmap(hdc,width,height); //copy HGDIOBJ old = ::SelectObject (memDC, bitmap); ::BitBlt(memDC,0,0,width,height,hdc,0,0,SRCCOPY); unsigned char *pixels = new unsigned char[width*height*4]; ::GetBitmapBits(bitmap,width*height*4,pixels); ::SelectObject (memDC, old); DeleteObject(bitmap); DeleteDC(memDC); DeleteDC(hdc); -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.233.186.250 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1403871440.A.DE6.html

06/27 21:17, , 1F
一個 pixel 用 4 bytes 存, 藍綠紅, 最後一個保留
06/27 21:17, 1F

06/28 09:15, , 2F
不保留可以嗎?
06/28 09:15, 2F

06/28 09:15, , 3F
另外請問我要怎麼把抓到的bitmap直接SHOW出來看?
06/28 09:15, 3F

06/28 09:57, , 4F
StretchBlt
06/28 09:57, 4F

06/28 17:53, , 5F
4是為了alignment 他struct就是這樣湊的
06/28 17:53, 5F
文章代碼(AID): #1JhM3Gtc (C_and_CPP)
文章代碼(AID): #1JhM3Gtc (C_and_CPP)