1.1.6-學習Opencv與MFC混合編程之---播放WAV音樂和 alpha融合功能

源代碼:http://download.csdn.net/detail/nuptboyzhb/3961698web

Alpha融合菜單項函數

1.      增長alpha融合菜單項,修改相應的屬性,創建類嚮導,編輯消息處理函數。spa

2.      在消息處理函數中添加以下代碼.net

void CCVMFCView::OnAlphaMix()code

{orm

//TODO: Add your command handler code here圖片

//TODO: Add your command handler code hereci

IplImage*src1, *src2;資源

CStringcsAVI="src1 Files(lena.bmp)|*.bmp|";it

   CString csFilter=csAVI;

CStringcsFilter2="src2 Files(gs76.bmp)|*.bmp|";

CStringname[]={"","bmp",""};

CStringstrFileName;

CStringstrExtension;

CFileDialogFileDlg(true,NULL,NULL,OFN_HIDEREADONLY,csFilter);

if(FileDlg.DoModal()==IDOK ) {        //  選擇了文件名

           strFileName= FileDlg.m_ofn.lpstrFile;

           if(FileDlg.m_ofn.nFileExtension == 0) { //  無文件後綴

                    strExtension= name[FileDlg.m_ofn.nFilterIndex];

                    strFileName= strFileName + '.' + strExtension;

                    //  加文件後綴

           }

           src1=cvLoadImage(strFileName);

           if(src1)

           {

          MessageBox("還須要打開一張圖片!");

           }

       CFileDialog FileDlg(true,NULL,NULL,OFN_HIDEREADONLY,csFilter2);

           if(FileDlg.DoModal()==IDOK ) {        //  選擇了文件名

                    strFileName= FileDlg.m_ofn.lpstrFile;

                    if(FileDlg.m_ofn.nFileExtension == 0) { //  無文件後綴

                             strExtension= name[FileDlg.m_ofn.nFilterIndex];

                             strFileName= strFileName + '.' + strExtension;

                             //  加文件後綴

           }

           src2=cvLoadImage(strFileName);

           cvNamedWindow("src1",CV_WINDOW_AUTOSIZE);

           cvMoveWindow("src1",300,300);

           cvShowImage("src1",src1);

           cvNamedWindow("src2",CV_WINDOW_AUTOSIZE);

           cvMoveWindow("src2",300+src1->width,300);

           cvShowImage("src2",src2);

           intx = 112;

       int y = 123;

       int width =src2->width;

       int height =src2->height;

       double alpha = 0.5;

       double beta  = 1-alpha;

       cvSetImageROI(src1, cvRect(x,y,width,height));

       cvSetImageROI(src2, cvRect(0,0,width,height));

       cvAddWeighted(src1, alpha, src2, beta,0.0,src1);

       cvResetImageROI(src1);

       cvNamedWindow( "Alpha_blend",CV_WINDOW_AUTOSIZE );

              cvMoveWindow("Alpha_blend",350+src1->width+src2->width,300);

       cvShowImage( "Alpha_blend", src1 );

       cvWaitKey(0);

           cvReleaseImage(&src1);

           cvReleaseImage(&src2);

           }

}

}


播放wav音樂

1.插入資源(插入->資源->定製->(輸入WAVA))

2.在resources中找到"WAVA"文件,打開有個IDR_WAVA1

3.右鍵->import->瀏覽後綴名爲.wav的音頻文件

4.在CXXXXView的構造函數中添加:

PlaySound(MAKEINTRESOURCE(IDR_TAOBAO_SENT_SOUND),AfxGetResourceHandle(),SND_ASYNC|SND_RESOURCE);

5.在該文件的上方,添加頭文件#include"mmsystem.h"

6.工程->設置->鏈接->庫模板添加"winmm.lib"

相關文章
相關標籤/搜索