2011年7月20日 星期三

Read Write BMP pixel

//============================================

// 將 BMP imagedata 放入 image buffer 中
//============================================
Gdiplus::Color pixelColor;
int myPixLocation;
unsigned char *imageBuffer = (unsigned char *)malloc(640*480*4);
for(int ix=0; ix<640; ix++)
{
for(int iy=0; iy<480; iy++)
{
pBitmap->GetPixel(ix, iy, &pixelColor);
myPixLocation = (iy*640+ix)*4;
imageBuffer[myPixLocation+0] = (unsigned char)pixelColor.GetR();
imageBuffer[myPixLocation+1] = (unsigned char)pixelColor.GetG();
imageBuffer[myPixLocation+2] = (unsigned char)pixelColor.GetB();
}
}

int myTmpPixLoc;
unsigned char *myOutBuffer = (unsigned char *)imageOut;
for(int ix=0; ix<640; ix++)
{
for(int iy=0; iy<480; iy++)
{
myTmpPixLoc = (iy*640+ix)*4;
pBitmap->SetPixel(ix, iy, Gdiplus::Color(myOutBuffer[myTmpPixLoc], myOutBuffer[myTmpPixLoc+1], myOutBuffer[myTmpPixLoc+2]) );
}
}

沒有留言:

張貼留言