|
发表于 2020-6-14 00:00:01
|
显示全部楼层
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; //设置成24位色(改起来方便,呵呵)
bmpG->Assign(bmpR); //和bmpR一样
bmpB->Assign(bmpR);
Byte *ptrR,*ptrG,*ptrB;
for (int y = 0; y < bmpR->Height; y++)
{
ptrR = (Byte *)bmpR->ScanLine[y]; //每行的像素颜色序列
ptrG = (Byte *)bmpG->ScanLine[y];
ptrB = (Byte *)bmpB->ScanLine[y];
for (int x = 0; x < bmpR->Width; x++) //对于24Bit图片每个像素点占三位
{
ptrB[x*3+1] = 0; //去除绿色分量
ptrB[x*3+2] = 0; //去除红色分量,剩下蓝色的
ptrG[x*3] = 0; //去除蓝色和红色分量,留下绿色的
ptrG[x*3+2] = 0;
ptrR[x*3] = 0; //同上
ptrR[x*3+1] = 0;
}
}
bmpR->SaveToFile("C:\\R.bmp"); //保存
bmpG->SaveToFile("C:\\G.bmp");
bmpB->SaveToFile("C:\\B.bmp");
delete bmpR;
delete bmpG;
delete bmpB;
}
BCB6.0测试通过,合并也差不多,改改就行了 |
|