I have this code, which executes several times during runtime:
// Restore the bitmap from the copy
IWICBitmapLock *pLock = NULL;
UINT cbStride = 0;
hr = m_pWICBitmapCopy->GetSize(&uiWidth,&uiHeight);
WICRect rcLock = { 0, 0, uiWidth, uiHeight };
hr = m_pWICBitmapCopy->Lock(&rcLock, WICBitmapLockRead, &pLock);
hr = pLock->GetDataPointer(&cbBufferSize, &pv);
hr = pLock->GetStride(&cbStride);
m_pWICBitmap->Release();
hr = m_pWICImagingFactory->CreateBitmapFromMemory(uiWidth,uiHeight,GUID_WICPixelFormat32bppPBGRA,cbStride,cbBufferSize,pv,&m_pWICBitmap);
hr = pLock->Release();
uiWidth
and uiHeight
always different, the initial value is 3264 and 2448. Second time it could be e.g. 778 and 246.
But method pLock->GetStride(&cbStride)
always returns the same stride value (in my case 13056). It causes that CreateBitmapFromMemory()
method creates a corrupted bitmap. Other variables are changing correctly depending on bitmap dimensions. It looks like pLock
cached stride value somewhere.
In MSDN written that, the stride value is specific to the IWICBitmapLock, not the bitmap. However, I did release pLock every time. So what could be the cause of such behavior?
The second way I could use to do the same is like this, but I want to understand what’s wrong with the code above.
m_pWICBitmap->Release();
m_pWICImagingFactory->CreateBitmapFromSource(m_pWICBitmapCopy, WICBitmapCacheOnDemand, &m_pWICBitmap);