裁剪影像

[與此頁面相關聯的功能 MCIWnd 視窗類別是舊版功能。 它已被 MediaPlayer 取代MediaPlayer已針對Windows 10和Windows 11進行優化。 Microsoft 強烈建議新程式碼盡可能使用 MediaPlayer ,而不是 MCIWnd 視窗類別。 Microsoft 建議盡可能重寫使用舊版 API 的現有程式碼,以使用新的 API。]

下列範例會建立 MCIWnd 視窗並載入 AVI 檔案。 視窗包含功能表中的裁剪命令,其會從框架四邊的四邊裁去一分之一的高度或寬度。 此範例會使用 MCIWndGetSource 宏,擷取目前 (來源矩形的初始) 維度。 修改過的來源矩形是原始高度和寬度的一半,而且會置中于原始框架中。 MCIWndPutSource宏的呼叫會重新定義來源矩形的座標。

// extern RECT rSource, rDest; 
 
case WM_COMMAND: 
    switch (wParam) 
    { 
        case IDM_CREATEMCIWND: 
            g_hwndMCIWnd = MCIWndCreate( hwnd, 
                g_hinst, 
                WS_CHILD | WS_VISIBLE, 
                "sample.avi" ); 
            break; 
        case IDM_CROPIMAGE:                          // crops image 
            MCIWndGetSource(g_hwndMCIWnd, &rSource); // source rectangle
            rDest.left = rSource.left +              // new boundaries
                ((rSource.right - rSource.left) / 4); 
            rDest.right = rSource.right - 
                ((rSource.right - rSource.left) / 4); 
            rDest.top = rSource.top + 
                ((rSource.bottom - rSource.top) / 4); 
            rDest.bottom = rSource.bottom - 
                ((rSource.bottom - rSource.top) / 4); 
 
            MCIWndPutSource(g_hwndMCIWnd, &rDest);   // new source rectangle 
    } 
    break; 

    // Handle other messages here.