BOOL ImageAnalyse(LPCTSTR szBMP) { //加载文件 HANDLE hBitmap = LoadImage (NULL, szBMP, IMAGE_BITMAP,0, 0, LR_LOADFROMFILE); ASSERT (hBitmap != NULL); //关联到位图 CBitmap m_bitmap; m_bitmap.Attach (hBitmap); //获取文件信息 BITMAP bm ={0}; m_bitmap.GetObject (sizeof (bm), &bm); //创建dc设备 HDC hDC = CreateDC(_T("DISPLAY"), 0, 0, 0); CDC dc; dc.Attach(hDC); CBitmap *pOldBmp = dc.SelectObject(&m_bitmap); //Add your code here for(int nRow=0; nRow<bm.bmWidth; nRow++) { for(int nCol=0; nCol<bm.bmHeight; nCol++) { COLORREF color = dc.GetPixel(nRow, nCol); TRACE( _T("RGB(%02X %02X %02X)"), GetRValue(color), GetGValue(color), GetBValue(color)); } TRACE(_T("/n")); } //恢复清理工作 dc.SelectObject(pOldBmp);//恢复位图 dc.Detach(); //解除关联 DeleteDC(hDC); //删除设备 m_bitmap.Detach(); //解除位图关联 DeleteObject(hBitmap); //删除位图 return TRUE; }