下面一段代码对BMP的象素操作非常有用:
void CBmpTryView::OnDraw(CDC* pDC)
{
CBmpTryDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CDC memdcX,memdcY;
memdcX.CreateCompatibleDC(pDC);
//map these CDC objects to your window DC
memdcY.CreateCompatibleDC(pDC);
BITMAP bmpX,bmpY;
CBitmap mybmp,bmpClone;
bmpClone.LoadBitmap(IDB_BITMAP2);
//initialize the clone bitmap object(empty image in
//this case) before using
DWORD dwValue,dwValue2;
if(TRUE == mybmp.LoadBitmap(IDB_BITMAP1))
{
mybmp.GetBitmap(&bmpX); //Get bitmap dimensions
//into BITMAP structure.
BYTE* bmpBuffer=(BYTE*)GlobalAlloc(GPTR,
bmpX.bmWidthBytes*bmpX.bmHeight);//allocate memory for image
//byte buffer
dwValue=mybmp.GetBitmapBits(bmpX.bmWidthBytes*bmpX.bmHeight,
bmpBuffer);//Get the bitmap bits
//into a structure
dwValue2 = bmpClone.SetBitmapBits(bmpX.bmWidthBytes*bmpX.bmHeight,
bmpBuffer);//generate image from
//above buffer
bmpClone.GetBitmap(&bmpY);
memdcX.SelectObject(mybmp);//select original bitmap






