星期二, 12月 14, 2010

[MFC] CImage 直接存取記憶體

//for 8-bit 影像
byte* pRealData=(byte*)m_Image.GetBits(); //取得記憶體開頭
int pit=m_Image.GetPitch(); //每一行的記憶體寬度
for (int y=0; y< Height;y++){
for (int x=0; x< Width;x++){
pRealData[ pit*y + x] = Intensity;

}}

//for 24-bit 影像

byte* pRealData=(byte*)SaveImg.GetBits();
int pit=SaveImg.GetPitch();
int bitCount=3;
for (int y=0; y< height; y++) {
for (int x=0; x< width; x++) {
pRealData [ pit*y + x*bitCount] = R ;
pRealData [ pit*y + x*bitCount+1] = G ;
pRealData [ pit*y + x*bitCount+2] = B;
}}