我加载了一个位图,位图大小为7397*4164,256级灰度(问一下256级灰度和256色图像有差别吗?),为什么我读进来的位图数据,在用SetPixel()显示的时候不正确呢?当我加载1024*768位图的时候就没有这个问题,这里用考虑4字节的对齐问题吗?急死了!//这是读入位图的函数
void CImageView::OnImageIn() 
{
memDC.SelectObject(oldObject);
m_pcbitmap.DeleteObject();
char szFilter[] = "Bitmap(*.BMP)|*.BMP||";
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFilter);
if(dlg.DoModal()==IDOK){
filename = dlg.GetPathName();
LoadBitmapFromFile(filename,m_pcbitmap);
}
m_pcbitmap.GetBitmap(m_pBitmap);

oldObject = memDC.SelectObject(&m_pcbitmap);

m_pcbBitmapBuffer = new char[m_pBitmap->bmWidth*m_pBitmap->bmHeight]; m_pcbitmap.GetBitmapBits( m_pBitmap->bmWidth*m_pBitmap->bmHeight, m_pcbBitmapBuffer ); ImageInFlag = 1;
}
//这是现实局部图像的函数
void CImageView::Inspection() 
{
// TODO: Add your command handler code here

int height;
int width;char* rectbitmap;

InspectionBox = CRect(0,0,200,200);

height = InspectionBox.Height()+1;
width  = InspectionBox.Width()+1;
CMainFrame* MainFrame=(CMainFrame*)this->GetParent()->GetParent(); 
    CDefectView* DefectView=(CDefectView*)MainFrame->m_wndSplitter.GetPane(0,1); 

CDC* DefectViewDC;
DefectViewDC = DefectView->GetDC(); for(int i=0;i<InspectionBox.Height();i++)
for(int j=0;j<InspectionBox.Width();j++)
{
int gray = m_pcbBitmapBuffer[i*m_pBitmap->bmWidth+j];//add CPoint pt(j,i);
DefectViewDC->SetPixel(pt,COLORREF(RGB(gray,gray,gray)));
}
}
当我把这个大小为7397*4164的位图,转成1024*768的就一切正常!什么原因呢?