MFC对话框播放8位512*512的像素数据
生活随笔
收集整理的這篇文章主要介紹了
MFC对话框播放8位512*512的像素数据
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
關(guān)鍵代碼:
UINT playAllFrame(LPVOID lpParameter){//showOneFrame(0,TRUE);CMFCDialogDlg *mydlg =(CMFCDialogDlg *) lpParameter;//獲取原始數(shù)據(jù)文件 CString selectPath;mydlg->GetDlgItemTextW(IDC_MFCEDITBROWSE,selectPath);string StrSelectPath(CW2A(selectPath.GetString()));const char * fileName = StrSelectPath.data();FILE *fin ; byte *pBmpData = (BYTE*)new char[bitmapWidth*bitmapHeight];//位圖數(shù)據(jù) BITMAPINFO * pBmpInfo = (BITMAPINFO *)new char[sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*256];for(int i = 0;i<256;i++){pBmpInfo->bmiColors[i].rgbRed = i;pBmpInfo->bmiColors[i].rgbGreen = i;pBmpInfo->bmiColors[i].rgbBlue = i;pBmpInfo->bmiColors[i].rgbReserved = 0;}//BITMAPINFO * pBmpInfo = new BITMAPINFO; pBmpInfo->bmiHeader.biBitCount = 8;pBmpInfo->bmiHeader.biClrImportant = 0;pBmpInfo->bmiHeader.biClrUsed = 0;pBmpInfo->bmiHeader.biCompression = 0;pBmpInfo->bmiHeader.biHeight = bitmapHeight;//這里是512pBmpInfo->bmiHeader.biPlanes = 0x01;pBmpInfo->bmiHeader.biSize = 40;pBmpInfo->bmiHeader.biSizeImage =262144;pBmpInfo->bmiHeader.biWidth = bitmapWidth;//這里是512pBmpInfo->bmiHeader.biXPelsPerMeter = 3780;pBmpInfo->bmiHeader.biYPelsPerMeter = 3780;errno_t er =fopen_s(&fin,fileName,"rb");if(er!=0){mydlg->MessageBox(L"文件打開失敗!");//break; }fseek(fin,0,SEEK_END);LONG fileSize = ftell(fin);fseek(fin,0,0);//計(jì)算總幀數(shù)int totalFrame = fileSize/(bitmapWidth*bitmapHeight);//設(shè)置下拉條范圍mydlg->m_slider.SetRange(1,totalFrame);//總幀數(shù)mydlg->m_lbl_total=totalFrame;CWnd *pWnd=mydlg->GetDlgItem(IDC_STATIC_PIC_2); //獲得pictrue控件窗口的句柄 CRect rect;pWnd->GetClientRect(&rect); //獲得pictrue控件所在的矩形區(qū)域CDC *pDC=pWnd->GetDC(); //獲得pictrue控件的DCpDC->SetStretchBltMode(COLORONCOLOR);while (TRUE){if(flag){long cur = ftell(fin)/(bitmapWidth*bitmapHeight);if(cur!=currentFrame&&(totalFrame>currentFrame||totalFrame>currentFrame)){fseek(fin,currentFrame*bitmapWidth*bitmapHeight,0);}if(!feof(fin)){fread(pBmpData,sizeof(BYTE),bitmapWidth*bitmapHeight,fin);StretchDIBits(pDC->GetSafeHdc(),0,0,rect.Width(),rect.Height(),0,0,bitmapWidth,bitmapHeight,pBmpData,pBmpInfo,DIB_RGB_COLORS,SRCCOPY);//Sleep(1);//當(dāng)前幀顯示值mydlg->m_lbl = currentFrame;//設(shè)置拉條位置mydlg->m_slider.SetPos(currentFrame);currentFrame = currentFrame +1;}else{flag = !flag;fseek(fin,0,0);currentFrame = 0;CButton *pBtn = (CButton *)mydlg->GetDlgItem(IDC_BUTTON2);pBtn->SetWindowTextW(_T("播放"));}}else{Sleep(200);}}fclose(fin);delete pBmpInfo;delete pBmpData;ExitThread(0);return 0; }運(yùn)行效果:
轉(zhuǎn)載于:https://www.cnblogs.com/airduce/p/9744810.html
總結(jié)
以上是生活随笔為你收集整理的MFC对话框播放8位512*512的像素数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 索尼、微软不再拖后腿 AMD锐龙7000
- 下一篇: iPhone 14爆料合集来了:然而十三