//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::dywc()
{
Byte * p;
int x, y;
Graphics::TBitmap * Bmp ;
byte gray ;
Bmp = new Graphics::TBitmap();
Bmp->Assign(Image2->Picture->Bitmap);
Bmp->PixelFormat = pf24bit;
for( y = 0 ;y< Bmp->Height ;y++)
{
p = (Byte *)Bmp->ScanLine[y];
for( x = 0; x< Bmp->Width - 1;x++ )
{
gray = (p[x * 3 + 2] * 0.3 + p[x * 3 + 1] * 0.59 + p[x* 3] * 0.11);
if ( gray < 63 )
{
//伪彩色处理的算法
p[x * 3 + 2] = 0;
p[x * 3 + 1] = 254 - 4 * gray;
p[x * 3] = 255;
}
if ( (64 <= gray) && (gray < 127) )
{
p[x * 3 + 2] = 0;
p[x * 3 + 1] = 4 * gray - 254;
p[x * 3] = 510 - 4 * gray;
}
if ( (128 <= gray) && (gray < 191) )
{
p[x * 3 + 2] = 4 * gray - 510;
p[x * 3 + 1] = 255;
p[x * 3] = 0;
}
if (192 <= gray)
{
p[x * 3 + 2] = 255;
p[x * 3 + 1] = 1022 - 4 * gray;
p[x * 3] = 0;
}
}
}
Image2->Picture->Bitmap->Assign(Bmp);
}
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
dywc();
}
//---------------------------------------------------------------------------
评论0