我試圖從位圖資源加載ID2D1Bitmap。爲此,我諮詢了一個MSDN guide,它告訴我在使用Direct2D之前使用Windows圖像處理組件(IWIC)處理圖像。IWICImagingFactory :: CreateDecoderFromStream()失敗,錯誤消息消息是沒有幫助的
但是,當我呼叫CreateDecoderFromStream()
時,它會失敗,並且它返回一個奇怪的錯誤消息 - 0x88982f50
- 它告訴我什麼都沒有。我搜索了Google並使用了DirectX Error Lookup。而DirectX錯誤查找工具,只告訴我:
HRESULT: 0x88982f50 (2291674960)
Name: Unknown
Description: n/a
Severity code: Failed
Facility Code: FACILITY_DWRITE (2200)
Error Code: 0x2f50 (12112)
這是我使用的嘗試,並從資源加載ID2D1Bitmap代碼:我不應該使用
int LoadBitmapFromResource(IWICImagingFactory *pIWICFactory, ID2D1RenderTarget *pRT, int resID, ID2D1Bitmap **ppD2DBitmap)
{
int errmsg;
HRSRC hbmp;
HGLOBAL hbmpdata;
void *pbmp; //system memory pointer to bitmap resource
DWORD bmpsize;
IWICStream *pStream;
IWICBitmapDecoder *pbmpdecoder;
IWICBitmapFrameDecode *pSource;
IWICFormatConverter *pConverter;
hbmp = FindResourceW(GetModuleHandleW(NULL), MAKEINTRESOURCEW(resID), RT_BITMAP);
if(NULL == hbmp)
{
printf("LoadBitmapFromResource::FindResourceW() error: %d\r\n", GetLastError());
return GetLastError();
}
hbmpdata = LoadResource(GetModuleHandleW(NULL), hbmp);
if(NULL == hbmpdata)
{
printf("LoadBitmapFromResource::LoadResource() error: %d\r\n", GetLastError());
return GetLastError();
}
pbmp = LockResource(hbmpdata);
if(NULL == pbmp)
{
printf("LoadBitmapFromResource::LockResource() error: %d\r\n", GetLastError());
return GetLastError();
}
bmpsize = SizeofResource(GetModuleHandleW(NULL), hbmp);
if(NULL == bmpsize)
{
printf("LoadBitmapFromResource::SizeofResource() error: %d\r\n", GetLastError());
return GetLastError();
}
errmsg = pIWICFactory->CreateStream(&pStream);
if(!SUCCEEDED(errmsg))
{
printf("LoadBitmapFromResource::CreateStream() error: %x\r\n", errmsg);
return errmsg;
}
errmsg = pStream->InitializeFromMemory((BYTE*)pbmp, bmpsize);
if(!SUCCEEDED(errmsg))
{
printf("LoadBitmapFromResource::InitializeFromMemory() error: %x\r\n", errmsg);
return errmsg;
}
errmsg = pIWICFactory->CreateDecoderFromStream(pStream, NULL, WICDecodeMetadataCacheOnLoad, &pbmpdecoder);
if(!SUCCEEDED(errmsg))
{
printf("LoadBitmapFromResource::CreateDecoderFromStream() error: %x\r\n", errmsg);
return errmsg;
}
errmsg = pbmpdecoder->GetFrame(0, &pSource);
if(!SUCCEEDED(errmsg))
{
printf("LoadBitmapFromResource::GetFrame() error: %x\r\n", errmsg);
return errmsg;
}
errmsg = pIWICFactory->CreateFormatConverter(&pConverter);
if(!SUCCEEDED(errmsg))
{
printf("LoadBitmapFromResource::CreateFormatConverter() error: %x\r\n", errmsg);
return errmsg;
}
errmsg = pConverter->Initialize(pSource, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, NULL, 0.0f, WICBitmapPaletteTypeMedianCut);
if(!SUCCEEDED(errmsg))
{
printf("LoadBitmapFromResource::Initialize() error: %x\r\n", errmsg);
return errmsg;
}
errmsg = pRT->CreateBitmapFromWicBitmap(pConverter, ppD2DBitmap);
if(!SUCCEEDED(errmsg))
{
printf("LoadBitmapFromResource::CreateBitmapFromWicBitmap() error: %x\r\n", errmsg);
return errmsg;
}
pConverter->Release();
pSource->Release();
pbmpdecoder->Release();
pStream->Release();
return 0;
}
這是一個WIC錯誤。它對應於'WINCODEC_ERR_COMPONENTNOTFOUND'。 [這裏](http://blogs.msdn.com/b/xwebsupport/archive/2009/09/29/expression-web-studio-2-crashes-on-setup-exception-has-been-thrown-by-你可能會發現一個可能對你有幫助的討論 – 2012-04-02 21:51:36
...我看到...我必須找到另一種方式從資源創建一個ID2D1Bitmap。 – Joshua 2012-04-03 04:10:12