2010年5月11日 星期二

BCB轉灰階code範例

Bitmap *result = new Bitmap();
result->PixelFormat = pf24bit;
result->Width = Image1->Picture->Bitmap->Width;
result->Height = Image1->Picture->Bitmap->Height;
for (int row = 0; row <>Picture->Bitmap->Height ; row++) {
   BYTE *Pixel1=(BYTE *)Image1->Picture->Bitmap->ScanLine[row];
   BYTE *Pixel2=(BYTE *)result->ScanLine[row];
   for (int col = 0; col <>Picture->Bitmap->Width ; col++) {
      Byte Gray = (*Pixel1+*(Pixel1+1)+*(Pixel1+2))/3;
      *Pixel2=*(Pixel2+1)=*(Pixel2+2) = Gray;
      Pixel1+=3;
      Pixel2+=3;
   }
}
Image2->Picture->Bitmap->Assign(result);
delete result;

沒有留言: