|
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Graphics::TBitmap *bmpR=new Graphics::TBitmap;
Graphics::TBitmap *bmpG=new Graphics::TBitmap;
Graphics::TBitmap *bmpB=new Graphics::TBitmap;
bmpR->LoadFromFile("C:\\test.bmp");
bmpR->PixelFormat=pf24bit; //Set to 24-bit color (easy to change, huh)
bmpG->Assign(bmpR); // same as bmpR
bmpB->Assign(bmpR);
Byte *ptrR, *ptrG, *ptrB;
for (int y = 0; y <bmpR->Height; y++)
{
ptrR = (Byte *)bmpR->ScanLine[y]; //Pixel color sequence of each line
ptrG = (Byte *)bmpG->ScanLine[y];
ptrB = (Byte *)bmpB->ScanLine[y];
for (int x = 0; x <bmpR->Width; x++) //For 24Bit pictures, each pixel occupies three bits
{
ptrB[x*3+1] = 0; //Remove the green component
ptrB[x*3+2] = 0; //Remove the red component and leave the blue one
ptrG[x*3] = 0; //Remove the blue and red components, leaving the green
ptrG[x*3+2] = 0;
ptrR[x*3] = 0; // Same as above
ptrR[x*3+1] = 0;
}
}
bmpR->SaveToFile("C:\\R.bmp"); //Save
bmpG->SaveToFile("C:\\G.bmp");
bmpB->SaveToFile("C:\\B.bmp");
delete bmpR;
delete bmpG;
delete bmpB;
}
The BCB6.0 test passed, and the merger is similar, just change it. |
|