Click here to Skip to main content
15,914,419 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a project for example about some image processing algorithm.
I open a bitmap file by using
C++
BOOL CImageProc_1Doc::OnOpenDocument(LPCTSTR lpszPathName)
{
	if (!CDocument::OnOpenDocument(lpszPathName))
		return FALSE;


	// TODO:  Add your specialized creation code here

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
C++
void CImageProc_1View::OnDraw(CDC*pDC)
{
	CImageProc_1Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;
	
	// TODO: add draw code for native data here

	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 :
C++
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!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900