我一直在使用 WIC 将多个图像编码为 JPEGXR 格式。 有时,我的程序会在我的编码函数的以下片段中记录最后一个 LogAssert 的错误。
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
最佳答案
这是并发调用 SetPixelFormat 时可能发生的问题。我听说它会在 Windows 8.1 中修复。
关于c++ - 是什么导致 IWICBitmapFrameEncode::SetPixelFormat 返回与请求格式不同的格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17711793/