我一直在使用WIC將多個圖像編碼爲JPEGXR格式。偶爾,我的程序在我的Encode函數的以下代碼片段中記錄了最後一個LogAssert的錯誤。什麼導致IWICBitmapFrameEncode :: SetPixelFormat返回一個與請求不同的格式?
hr = m_pFactory->CreateEncoder(GUID_ContainerFormatWmp, NULL, &pEncoder);
LogAssert(SUCCEEDED(hr),"Failed to create encoder. Err: 0x%x", hr);
hr = pEncoder->Initialize(pOutputStream, WICBitmapEncoderNoCache);
LogAssert(SUCCEEDED(hr),"Failed to initialize encoder. Err: 0x%x", hr);
hr = pEncoder->CreateNewFrame(&pBitmapFrame, &pPropertyBag);
LogAssert(SUCCEEDED(hr),"Encoder failed to create new frame. Err: 0x%x", hr);
SetEncodingProperties(pPropertyBag);
hr = pBitmapFrame->Initialize(pPropertyBag);
LogAssert(SUCCEEDED(hr),"Failed to initialize pBitmapFrame with the given properties. Err: 0x%x", hr);
hr = pBitmapFrame->SetSize(rawWidth, rawHeight);
LogAssert(SUCCEEDED(hr),"Failed to set bitmap size. Err: 0x%x", hr);
WICPixelFormatGUID formatGUID = GUID_WICPixelFormat24bppBGR;
hr = pBitmapFrame->SetPixelFormat(&formatGUID);
if(FAILED(hr) || !IsEqualGUID(formatGUID, GUID_WICPixelFormat24bppBGR))
{
LogAssert(false,"Failed to set pixel format to GUID_WICPixelFormat24bppBGR. Err: 0x%x", hr);
}
我檢查轉儲文件,它似乎返回formatGUID是GUID_WICPixelFormat24bpp RGB。
我有以下問題:
什麼時候對setPixel格式返回不同的版本?什麼因素可能導致它返回一個不同的GUID?
我總是編碼爲JPEGXR,並始終應用相同的屬性。爲什麼SetPixelFormat的行爲是非確定性的?它不應該總是成功,或者總是返回GUID_WICPixelFormat24bppRGB?
如果支持RGB格式,爲什麼不是BGR?這只是一種改變。
我的代碼,寫用例的幫助在這裏:
http://msdn.microsoft.com/en-us/library/windows/desktop/ee719871(v=vs.85).aspx