ScanLine을 사용하여 간단히
이미지의 gray톤, blue톤, red톤, yellow톤 처리입니다.
//* 먼저 Image 두개, PaintBox 1개를 만들고 두개의 이미지에는 BMP그림을 불러와 있어야 합니다.
// 모두 동일한 사각형 영역
void __fastcall TForm1::Button1Click(TObject *Sender)
{
RGBTRIPLE *rtColor,*rtColor2;
int x,y;
TColor avgcolor;
TMemoryStream* pms = new TMemoryStream();
Image1->Picture->Bitmap->SaveToStream(pms);
pms->Position = 0;
Image2->Picture->Bitmap->LoadFromStream(pms);
for(y=30;y<Image1->Height-30;y++)
{
rtColor=(RGBTRIPLE*)Image1->Picture->Bitmap->ScanLine[y]; // Image1에서 읽어
rtColor2=(RGBTRIPLE*)Image2->Picture->Bitmap->ScanLine[y]; // Image2로 변환
for(x=0;x<Image1->Width;x++)
{
avgcolor=(TColor)(rtColor[x].rgbtRed*3
+rtColor[x].rgbtGreen*9
+rtColor[x].rgbtBlue)/13;
rtColor2[x].rgbtRed=avgcolor; // R, G, B중 값을 0로 하면 Blue톤
rtColor2[x].rgbtGreen=avgcolor; // Red톤, Yellow톤 등 다양한 톤을 만들 수 있습니다.
rtColor2[x].rgbtBlue=avgcolor;
}
}
PaintBox1->Canvas->Draw(0,0,Image2->Picture->Bitmap); // 최종 PaintBox로 복사
}
1. Red톤
rtColor2[x].rgbtRed=avgcolor;
rtColor2[x].rgbtGreen=0;
rtColor2[x].rgbtBlue=0;
2. Green톤
rtColor2[x].rgbtRed=0;
rtColor2[x].rgbtGreen=avgcolor;
rtColor2[x].rgbtBlue=0;
3. Blue톤
rtColor2[x].rgbtRed=0;
rtColor2[x].rgbtGreen=0;
rtColor2[x].rgbtBlue=avgclolor;
4. Yellow톤
rtColor2[x].rgbtRed=avgcolor;
rtColor2[x].rgbtGreen=avgcolor;
rtColor2[x].rgbtBlue=0;
|