获取图片的RGB分量

void  CShowBMPDlg::GetRGB(CDC &  dcPic)
{
    std::ofstream ofsCOLOR;
    ofsCOLOR.open(strPathName
+"_rgb.h");

    
int i=0, j=0;
    
int r=0,g=0,b=0;    
    unsigned 
int cRGB=0;

    COLORREF c;
    ofsCOLOR 
<< "const U32 picData[] = " << std::endl;
    ofsCOLOR 
<< "{";
    ofsCOLOR 
<< std::setfill('0');
    ofsCOLOR 
<< std::setbase(16);

    ofsCOLOR 
<< "0x" << std::setw(8<< m_bmW << "," 
             
<< "0x" << std::setw(8<< m_bmH << "," << std::endl;

    
for(i=0; i<m_bmH; ++i)//
    {    
        
for(j=0; j<m_bmW; ++j)//
        {
            c 
= dcPic.GetPixel(j,i); //(x,y)==(j,i)
            
            
//ofsCOLOR << c << " ";
            r = c & 0x0000ff;
            g 
= (c & 0x00ff00>> 8;
            b 
= (c & 0xff0000>> 16;

            cRGB 
= r << 16 | g << 8 | b;
            ofsCOLOR 
<< "0x" << std::setw(8<< cRGB << ",";

        
//    ofsCOLOR << "0x" << std::setw(2) << b << ","
        
//             << "0x" << std::setw(2) << g << ","
        
//             << "0x" << std::setw(2) << r << ","
        
//             << "0x" << std::setw(2) << 0 << "," ;
        }

        ofsCOLOR 
<< std::endl;
    }

    ofsCOLOR 
<< "};" << std::endl;

    ofsCOLOR.close();

}
 

你可能感兴趣的:(获取图片的RGB分量)