⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.cpp

📁 处理黑白图片
💻 CPP
字号:
//---------------------------------------------------------------------------

#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();        
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -