The format should be
GUID_WICPixelFormat32bppPBGRA
(not GUID_WICPixelFormat32bppBGRA)
(I copied/pasted your code, similar as MSDN code and it worked with this format, like in MS samples)
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
So, I've wrote the following code but for some reason I am not aware of, CreateBitmapFromWicBitmap is throwing errors. Here's the code:
SpriteSheet::SpriteSheet(const wchar_t* filename, MainWindow* mw){
bmap = NULL;
HRESULT hr;
IWICImagingFactory *wicFactory = NULL;
hr = CoCreateInstance(CLSID_WICImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWICImagingFactory,
(LPVOID *)&wicFactory);
if(hr != S_OK){
return;
}
IWICBitmapDecoder *wicDecoder = NULL;
hr = wicFactory->CreateDecoderFromFilename(
filename,
NULL,
GENERIC_READ,
WICDecodeMetadataCacheOnLoad,
&wicDecoder
);
if(hr != S_OK){
return;
}
IWICBitmapFrameDecode *wicFrame = NULL;
hr = wicDecoder->GetFrame(0,&wicFrame);
if(!SUCCEEDED(hr)){
std::cout<<"error"<<std::endl;
}
IWICFormatConverter *wicConverter;
hr = wicFactory->CreateFormatConverter(&wicConverter);
if(!SUCCEEDED(hr)){
std::cout<<"error"<<std::endl;
}
hr = wicConverter->Initialize(wicFrame,
GUID_WICPixelFormat32bppBGRA,
WICBitmapDitherTypeNone,
NULL,
0.0,
WICBitmapPaletteTypeCustom);
hr = mw->GetRenderTarget()->CreateBitmapFromWicBitmap(
wicConverter,
NULL,
&bmap
);
if(!SUCCEEDED(hr)){
std::cout<<"error"<<std::endl;
}
if(wicFrame) wicFrame->Release();
if(wicFactory) wicFactory->Release();
if(wicDecoder) wicDecoder->Release();
if(wicConverter) wicConverter->Release();
}
the error code is: 12160
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
Answer accepted by question author
The format should be
GUID_WICPixelFormat32bppPBGRA
(not GUID_WICPixelFormat32bppBGRA)
(I copied/pasted your code, similar as MSDN code and it worked with this format, like in MS samples)