I have a project for example about some image processing algorithm.
I open a bitmap file by using
BOOL CImageProc_1Doc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
hBitmap=(HBITMAP)::LoadImage (AfxGetInstanceHandle(), lpszPathName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE | LR_CREATEDIBSECTION);
if(m_bmBitmap.DeleteObject ()) m_bmBitmap.Detach ();
m_bmBitmap.Attach (hBitmap);
}
I draw the image using this code
void CImageProc_1View::OnDraw(CDC*pDC)
{
CImageProc_1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
if (pDoc->m_bmBitmap.m_hObject ==NULL ) return;
BITMAP bm;
pDoc->m_bmBitmap.GetBitmap (&bm);
CDC dcMem;
dcMem.CreateCompatibleDC (pDC);
dcMem.SelectObject (pDoc->m_bmBitmap );
::SetDIBColorTable(dcMem,0,256,pDoc->rgb);
pDC->StretchBlt(0,0,bm .bmWidth ,bm.bmHeight ,&dcMem,0,0,bm.bmWidth ,bm.bmHeight ,SRCCOPY);
}
Now I process the bitmap data (store in bm.bmBits pointer) , I store the result in a other newBit pointer and try this code :
dw=::SetBitmapBits(pDlgDoc->hBitmap,bm.bmHeight*bm.bmWidthBytes,newBit);
It's only work well when the bitmap has no padding buffer
although the newBit has padding bytes.
When the bitmap has padding , the bitmap is drawn in wrong way like
THIS
Please help me solve this problem , Thanks all!