zoukankan      html  css  js  c++  java
  • MFC对话框播放8位512*512的像素数据

    关键代码:

    UINT playAllFrame(LPVOID lpParameter){
        //showOneFrame(0,TRUE);
        CMFCDialogDlg *mydlg =(CMFCDialogDlg *)  lpParameter;
    
        //获取原始数据文件
        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];//位图数据
        
        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;//这里是512
        pBmpInfo->bmiHeader.biPlanes = 0x01;
        pBmpInfo->bmiHeader.biSize = 40;
        pBmpInfo->bmiHeader.biSizeImage =262144;
        pBmpInfo->bmiHeader.biWidth = bitmapWidth;//这里是512
        pBmpInfo->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);
    
        //计算总帧数
        int totalFrame = fileSize/(bitmapWidth*bitmapHeight);
    
        //设置下拉条范围
        mydlg->m_slider.SetRange(1,totalFrame);
    
        //总帧数
        mydlg->m_lbl_total=totalFrame;
    
        CWnd *pWnd=mydlg->GetDlgItem(IDC_STATIC_PIC_2); //获得pictrue控件窗口的句柄
        CRect rect;
        pWnd->GetClientRect(&rect); //获得pictrue控件所在的矩形区域
        CDC *pDC=pWnd->GetDC(); //获得pictrue控件的DC
        pDC->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);
                    //当前帧显示值
                    mydlg->m_lbl = currentFrame;
                    //设置拉条位置
                    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;
    }

    运行效果:

  • 相关阅读:
    程序员找工作必备 PHP 基础面试题 (四)
    Laravel 教程:使用Fast Excel解决导出超大 XLSX 文件(千万级)带来的内存问题
    ThinkPHP无限分类的使用
    PHP 的 interface 有什么用处?
    编写可读代码:通过提前返回来减少缩进
    调试事件的派发
    调试对象的构建
    [反汇编分析] 局部变量复用
    [IDA]批量载入结构体
    [反汇编分析]调用函数传入参数不一致时可能寄存器传入参数
  • 原文地址:https://www.cnblogs.com/airduce/p/9744810.html
Copyright © 2011-2022 走看看