共用方式為


如何調整點陣圖來源

本主題示範如何使用IWICBitmapScaler元件調整IWICBitmapSource

縮放點陣圖來源

  1. 建立 IWICImagingFactory 物件,以在 WIC) 物件 (建立 Windows 映像元件。

    // Create WIC factory
    hr = CoCreateInstance(
        CLSID_WICImagingFactory,
        NULL,
        CLSCTX_INPROC_SERVER,
        IID_PPV_ARGS(&m_pIWICFactory)
        );
    
  2. 使用 CreateDecoderFromFilename 方法,從影像檔建立 IWICBitmapDecoder

    HRESULT hr = S_OK;
    
    IWICBitmapDecoder *pIDecoder = NULL;
    IWICBitmapFrameDecode *pIDecoderFrame  = NULL;
    IWICBitmapScaler *pIScaler = NULL;
    
    
    hr = m_pIWICFactory->CreateDecoderFromFilename(
       L"turtle.jpg",                  // Image to be decoded
       NULL,                           // Do not prefer a particular vendor
       GENERIC_READ,                   // Desired read access to the file
       WICDecodeMetadataCacheOnDemand, // Cache metadata when needed
       &pIDecoder                      // Pointer to the decoder
       );
    
  3. 取得影像的第一個 IWICBitmapFrameDecode

    // Retrieve the first bitmap frame.
    if (SUCCEEDED(hr))
    {
       hr = pIDecoder->GetFrame(0, &pIDecoderFrame);
    }
    

    JPEG 檔案格式僅支援單一框架。 因為此範例中的檔案是 JPEG 檔案,所以會使用第一個框架 (0) 。 如需具有多個畫面的影像格式,請參閱如何擷取 影像的畫面格 ,以存取影像的每個畫面格。

  4. 建立要用於影像縮放的 IWICBitmapScaler

    // Create the scaler.
    if (SUCCEEDED(hr))
    {
       hr = m_pIWICFactory->CreateBitmapScaler(&pIScaler);
    }
    
  5. 使用點陣圖框架的影像資料初始化縮放器物件,大小為一半。

    // Initialize the scaler to half the size of the original source.
    if (SUCCEEDED(hr))
    {
       hr = pIScaler->Initialize(
          pIDecoderFrame,                    // Bitmap source to scale.
          uiWidth/2,                         // Scale width to half of original.
          uiHeight/2,                        // Scale height to half of original.
          WICBitmapInterpolationModeFant);   // Use Fant mode interpolation.
    }
    
  6. 繪製或處理縮放點陣圖來源。

    下圖示范映射調整。 左側的原始影像為 200 x 130 圖元。 右邊的影像是原始影像會縮放為大小一半。

    顯示將影像縮放至較小大小的圖例

另請參閱

程式設計指南

參考

範例