C++ Direct2D ID2D1RenderTarget::CreateBitmapFromWicBitmap失败,无错误
我只是尝试将LoadBitmapFromFile函数从示例(来自SDK)添加到我的MFC项目中。所以我的应用程序在运行时在线失败,没有错误,没有警告C++ Direct2D ID2D1RenderTarget::CreateBitmapFromWicBitmap失败,无错误,c++,mfc,direct2d,C++,Mfc,Direct2d,我只是尝试将LoadBitmapFromFile函数从示例(来自SDK)添加到我的MFC项目中。所以我的应用程序在运行时在线失败,没有错误,没有警告 hr = pRenderTarget->CreateBitmapFromWicBitmap(pConverter, NULL, ppBitmap); 当我调试它并越过这一行时,我收到一个空窗口,调试会话停止。如何找出错误是什么?原因可能是什么 HRESULT DemoApp::LoadBitmapFromFile( ID2D1Rende
hr = pRenderTarget->CreateBitmapFromWicBitmap(pConverter, NULL, ppBitmap);
当我调试它并越过这一行时,我收到一个空窗口,调试会话停止。如何找出错误是什么?原因可能是什么
HRESULT DemoApp::LoadBitmapFromFile(
ID2D1RenderTarget *pRenderTarget,
IWICImagingFactory *pIWICFactory,
PCWSTR uri,
UINT destinationWidth,
UINT destinationHeight,
ID2D1Bitmap **ppBitmap)
{
HRESULT hr = S_OK;
IWICBitmapDecoder *pDecoder = NULL;
IWICBitmapFrameDecode *pSource = NULL;
IWICStream *pStream = NULL;
IWICFormatConverter *pConverter = NULL;
IWICBitmapScaler *pScaler = NULL;
hr = pIWICFactory->CreateDecoderFromFilename(
uri,
NULL,
GENERIC_READ,
WICDecodeMetadataCacheOnLoad,
&pDecoder
);
if (SUCCEEDED(hr))
{
// Create the initial frame.
hr = pDecoder->GetFrame(0, &pSource);
}
if (SUCCEEDED(hr))
{
// Convert the image format to 32bppPBGRA
// (DXGI_FORMAT_B8G8R8A8_UNORM + D2D1_ALPHA_MODE_PREMULTIPLIED).
hr = pIWICFactory->CreateFormatConverter(&pConverter);
}
if (SUCCEEDED(hr))
{
// If a new width or height was specified, create an
// IWICBitmapScaler and use it to resize the image.
if (destinationWidth != 0 || destinationHeight != 0)
{
UINT originalWidth, originalHeight;
hr = pSource->GetSize(&originalWidth, &originalHeight);
if (SUCCEEDED(hr))
{
if (destinationWidth == 0)
{
FLOAT scalar = static_cast<FLOAT>(destinationHeight) / static_cast<FLOAT>(originalHeight);
destinationWidth = static_cast<UINT>(scalar * static_cast<FLOAT>(originalWidth));
}
else if (destinationHeight == 0)
{
FLOAT scalar = static_cast<FLOAT>(destinationWidth) / static_cast<FLOAT>(originalWidth);
destinationHeight = static_cast<UINT>(scalar * static_cast<FLOAT>(originalHeight));
}
hr = pIWICFactory->CreateBitmapScaler(&pScaler);
if (SUCCEEDED(hr))
{
hr = pScaler->Initialize(
pSource,
destinationWidth,
destinationHeight,
WICBitmapInterpolationModeCubic
);
}
if (SUCCEEDED(hr))
{
hr = pConverter->Initialize(
pScaler,
GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone,
NULL,
0.f,
WICBitmapPaletteTypeMedianCut
);
}
}
}
else // Don't scale the image.
{
hr = pConverter->Initialize(
pSource,
GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone,
NULL,
0.f,
WICBitmapPaletteTypeMedianCut
);
}
}
if (SUCCEEDED(hr))
{
// Create a Direct2D bitmap from the WIC bitmap.
hr = pRenderTarget->CreateBitmapFromWicBitmap(pConverter, NULL, ppBitmap);
}
SafeRelease(&pDecoder);
SafeRelease(&pSource);
SafeRelease(&pStream);
SafeRelease(&pConverter);
SafeRelease(&pScaler);
return hr;
HRESULT DemoApp::LoadBitmapFromFile(
ID2D1RenderTarget*pRenderTarget,
IwicingFactory*pIWICFactory,
PCWSTR uri,
单位目标宽度,
目的地高度,
ID2D1Bitmap**pp位图)
{
HRESULT hr=S_正常;
IWICBitmapDecoder*pDecoder=NULL;
IWICBitmapFrameDecode*pSource=NULL;
IWICStream*pStream=NULL;
IWICFormatConverter*pConverter=NULL;
IWICBitmapScaler*pScaler=NULL;
hr=pIWICFactory->CreateDecoderFromFilename(
乌里,
无效的
泛读,
WicDecodataCacheOnLoad,
&光电编码器
);
如果(成功(hr))
{
//创建初始帧。
hr=pDecoder->GetFrame(0,&pSource);
}
如果(成功(hr))
{
//将图像格式转换为32bppPBGRA
//(DXGI格式B8G8R8A8 UNORM+D2D1阿尔法模式预乘)。
hr=pIWICFactory->CreateFormatConverter(&pConverter);
}
如果(成功(hr))
{
//如果指定了新的宽度或高度,请创建
//IWICBitmapScaler并使用它调整图像大小。
如果(destinationWidth!=0 | | destinationHeight!=0)
{
UINT原始宽度、原始高度;
hr=pSource->GetSize(&originalWidth,&originalHeight);
如果(成功(hr))
{
如果(destinationWidth==0)
{
浮动标量=静态投影(目标高度)/静态投影(原始高度);
destinationWidth=静态施法(标量*静态施法(原始宽度));
}
else if(destinationHeight==0)
{
浮动标量=静态施法(目标宽度)/静态施法(原始宽度);
destinationHeight=静态施法(标量*静态施法(原始高度));
}
hr=pIWICFactory->CreateBitmapScaler(&pScaler);
如果(成功(hr))
{
hr=pScaler->初始化(
pSource,
目的地宽度,
目的地高度,
WICBitmapInterpolationModeCubic
);
}
如果(成功(hr))
{
hr=pConverter->初始化(
pScaler,
GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone,
无效的
0.f,
WICBitmapPaletteTypeMedianCut
);
}
}
}
否则//不要缩放图像。
{
hr=pConverter->初始化(
pSource,
GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone,
无效的
0.f,
WICBitmapPaletteTypeMedianCut
);
}
}
如果(成功(hr))
{
//从WIC位图创建Direct2D位图。
hr=pRenderTarget->CreateBitmapFromWicBitmap(pConverter,NULL,ppBitmap);
}
安全释放(&pDecoder);
安全释放(&pSource);
安全释放(&pStream);
安全释放装置(和转换装置);
安全释放(&pScaler);
返回人力资源;
}D2D调试层告诉我们什么<代码>D2FactoryOptions.debugLevel=D2D1调试级别信息不幸的是,它什么也没说,只是沉默。