16,472
社区成员
发帖
与我相关
我的任务
分享
LPBITMAPINFOHEADER alpbi; //记录屏幕信息的位图,,,帧
alpbi=captureScreenFrame(left,top,width, height,1); //截取的屏幕 并已经封装成帧
if (flashingRect) { // Set Up Flashing Rect、、、这是干嘛用的没搞懂 求解释
pFrame->SetUpRegion(left,top,width,height,0);
pFrame->ShowWindow(SW_SHOW);
}
//然后就是AVI文件流压缩器的初始化。。。省略一大堆。。。
FreeFrame(alpbi);//刚才截取的那一帧 没用就释放了。。。。,难道是用于初始化AVI
alpbi=NULL;
//录像重这里真正的开始。。。。
while(1)
{
alpbi=captureScreenFrame(left,top,width, height,0);//最后一个参数变成了 0
hr = AVIStreamWrite(psCompressed, // stream pointer
frametime, // time of this frame
1, // number to write
(LPBYTE) alpbi + // pointer to data
alpbi->biSize +
alpbi->biClrUsed * sizeof(RGBQUAD),
alpbi->biSizeImage, // size of this frame
//AVIIF_KEYFRAME, // flags....
0, //Dependent n previous frame, not key frame
NULL,
NULL);
nActualFrame ++ ;//帧数 加1
InvalidateRect(NULL, NULL, FALSE);//声明客户区无效,重画时不擦除背景??
FreeFrame(alpbi);
alpbi=NULL;
Sleep(5);//
}
然后下面是captureScreenFrame的实现:
LPBITMAPINFOHEADER captureScreenFrame(int left,int top,int width, int height,int tempDisableRect)
{
HANDLE hdib ;
HDC hdc ;
BITMAP bitmap ;
UINT wLineLen ;
DWORD dwSize ;
DWORD wColSize ;
LPBITMAPINFOHEADER lpbi ;
LPBYTE lpBits ;
//tempDisableRect仅初始化AVI的时候为 1 , 录像阶段永远为 0 ,包挎第一帧
if (flashingRect && !tempDisableRect) {//???????????
DrawFlashingRect( TRUE , 0);
}
wLineLen = (width*bits+31)/32 * 4;//计算位图每行占多少个字节
wColSize = sizeof(RGBQUAD)*((bits <= 8) ? 1<<bits : 0);//0
dwSize = sizeof(BITMAPINFOHEADER) + wColSize +
(DWORD)(UINT)wLineLen*(DWORD)(UINT)height;
//
// Allocate room for a DIB and set the LPBI fields
hdib = GlobalAlloc(GHND,dwSize);
if (!hdib)
exit(1) ;
lpbi = (LPBITMAPINFOHEADER)GlobalLock(hdib) ;
lpbi->biSize = sizeof(BITMAPINFOHEADER) ;
lpbi->biWidth = width ;
lpbi->biHeight = height ;
lpbi->biPlanes = 1 ;//The number of planes for the target device. This value must be set to 1.
lpbi->biBitCount = (WORD) bits ;//灰度图像(biBitCount=8)彩色图像(biBitCount=24)
lpbi->biCompression = BI_RGB ;//BI_RGB An uncompressed format.
lpbi->biSizeImage = dwSize - sizeof(BITMAPINFOHEADER) - wColSize ;//位图所占字节
lpbi->biXPelsPerMeter = 0 ;
lpbi->biYPelsPerMeter = 0 ;
lpbi->biClrUsed = (bits <= 8) ? 1<<bits : 0;
lpbi->biClrImportant = 0 ;
//
// Get the bits from the bitmap and stuff them after the LPBI
lpBits = (LPBYTE)(lpbi+1)+wColSize ;
if (videodriver.myframebuffer)//设置像素,每一帧
SETPIXELS_NOCONV((BYTE *)videodriver.myframebuffer,lpBits, left, top, width, height,bits,maxxScreen);
GlobalUnlock(hdib);
LPBITMAPINFOHEADER pBM_HEADER = (LPBITMAPINFOHEADER)GlobalLock(hdib);//锁定一个全局内存对象并返回一个指向对象的内存块的第一个字节。
//LPBITMAPINFOHEADER pBM_HEADER = (LPBITMAPINFOHEADER)GlobalLock(Bitmap2Dib(hbm, 24));
if (pBM_HEADER == NULL) {
//MessageBox(NULL,"Error reading a frame!","Error",MB_OK | MB_ICONEXCLAMATION);
MessageOut(NULL,IDS_STRING_ERRFRAME ,IDS_STRING_NOTE,MB_OK | MB_ICONEXCLAMATION);
exit(1);
}
//if flashing rect
if (flashingRect && !tempDisableRect) {
DrawFlashingRect(FALSE , 0);
}
return pBM_HEADER;
}
void DrawFlashingRect(BOOL bDraw , int mode) {
if (mode == 1) {
pFrame->PaintInvertedBorder(RGB(0,255,80));//绘画倒转的边框,永不执行
}
else {
if (bDraw)
pFrame->PaintBorder(RGB(255,255,180));
else
pFrame->PaintBorder(RGB(0,255,80));
}
}
void CFlashingWnd::PaintBorder(COLORREF colorval)
{
// Add your drawing code here!
HDC hdc = ::GetDC(m_hWnd);
if ((cRect.right>cRect.left) && (cRect.bottom>cRect.top)) {
HBRUSH newbrush = (HBRUSH) CreateSolidBrush( colorval);
HBRUSH newpen = (HBRUSH) CreatePen(PS_SOLID,1, colorval);
HBRUSH oldbrush = (HBRUSH) SelectObject(hdc,newbrush);
HBRUSH oldpen = (HBRUSH) SelectObject(hdc,newpen);
Rectangle(hdc,cRect.left-THICKNESS,cRect.top-THICKNESS,cRect.right+THICKNESS,cRect.bottom+THICKNESS);
SelectObject(hdc,oldpen);
SelectObject(hdc,oldbrush);
DeleteObject(newpen);
DeleteObject(newbrush);
}
::ReleaseDC(m_hWnd,hdc);
}