Код: Выделить всё
hr = this->pRenderTarget->CreateBitmapFromWicBitmap(pConverter, NULL, ppBitmap);Код: Выделить всё
CoInitializeEx(NULL, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE);
CoCreateInstance(
CLSID_WICImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&this->pWIC)
);
hr = this->pFactory->CreateHwndRenderTarget(
RenderTargetProperties(),
HwndRenderTargetProperties(hWnd, size),
&this->pRenderTarget
);
void LoadBitmapFromFile(PCWSTR uri, ID2D1Bitmap** ppBitmap)
{
while (this->loading) {
std::this_thread::sleep_for(std::chrono::microseconds(1));
}
this->loading = true;
IWICBitmapDecoder* pDecoder = NULL;
IWICBitmapFrameDecode* pSource = NULL;
IWICStream* pStream = NULL;
IWICFormatConverter* pConverter = NULL;
IWICBitmapScaler* pScaler = NULL;
*ppBitmap = 0;
HRESULT hr = this->pWIC->CreateDecoderFromFilename(
uri,
NULL,
GENERIC_READ,
WICDecodeMetadataCacheOnLoad,
&pDecoder
);
if (FAILED(hr))
{
MessageBox(HWND_DESKTOP, _T("ERROR: Failed to Create the iWIC factory."),
_T("DirectWrite Error"), MB_OK | MB_ICONERROR);
}
if (SUCCEEDED(hr))
{
hr = pDecoder->GetFrame(0, &pSource);
}
if (SUCCEEDED(hr))
{
hr = this->pWIC->CreateFormatConverter(&pConverter);
}
if (SUCCEEDED(hr))
{
hr = pConverter->Initialize(
pSource,
GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone,
NULL,
0.f,
WICBitmapPaletteTypeMedianCut
);
}
if (SUCCEEDED(hr))
{
hr = this->pRenderTarget->CreateBitmapFromWicBitmap(pConverter, NULL, ppBitmap);
}
SafeRelease(&pDecoder);
SafeRelease(&pSource);
SafeRelease(&pStream);
SafeRelease(&pConverter);
SafeRelease(&pScaler);
this->loading = false;
return;
}
Подробнее здесь: https://stackoverflow.com/questions/781 ... tithreaded