Bagikan melalui


Mengompresi Data

[Fitur yang terkait dengan halaman ini, Video Compression Manager, adalah fitur warisan. Microsoft sangat menyarankan agar kode baru tidak menggunakan fitur ini.]

Contoh berikut mengompresi data gambar untuk digunakan dalam file AVI. Ini mengasumsikan kompresor tidak mendukung bendera VIDCF_CRUNCH atau VIDCF_TEMPORAL, tetapi mendukung VIDCF_QUALITY. Contohnya menggunakan makro ICCompressBegin, fungsi ICCompress, dan makro ICCompressEnd.

DWORD dwCkID; 
DWORD dwCompFlags; 
DWORD dwQuality; 
LONG  lNumFrames, lFrameNum; 
// Assume dwNumFrames is initialized to the total number of frames. 
// Assume dwQuality holds the proper quality value (0-10000). 
// Assume lpbiOut, lpOut, lpbiIn, and lpIn are initialized properly. 
 
// If OK to start, compress each frame. 
if (ICCompressBegin(hIC, lpbiIn, lpbiOut) == ICERR_OK)
{ 
    for ( lFrameNum = 0; lFrameNum < lNumFrames; lFrameNum++)
    { 
        if (ICCompress(hIC, 0, lpbiOut, lpOut, lpbiIn, lpIn, 
            &dwCkID, &dwCompFlags, lFrameNum, 
            0, dwQuality, NULL, NULL) == ICERR_OK)
        { 
            // Write compressed data to the AVI file. 
             
            // Set lpIn to the next frame in the sequence. 
             
        } 
        else 
        { 
            // Handle compressor error. 
        } 
    } 
    ICCompressEnd(hIC);    // terminate compression 
} 
else 
{ 
    // Handle the error identifying the unsupported format. 
}