Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:1k
源码类别:

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. //---------------------------------------------------------------------------
  10. __fastcall TForm1::TForm1(TComponent* Owner)
  11.         : TForm(Owner)
  12. {
  13. }
  14. //---------------------------------------------------------------------------
  15. void __fastcall TForm1::Button1Click(TObject *Sender)
  16. {
  17.   int ii,jj,pix,pix1;
  18.   byte cr,cg,cb;
  19.   for(jj=0;jj<Image1->Height;jj++)
  20.     for(ii=0;ii<Image1->Width;ii++)
  21.     {
  22.       pix=Image1->Picture->Bitmap->Canvas->Pixels[ii][jj];
  23.       cr=GetRValue(pix);
  24.       cg=GetGValue(pix);
  25.       cb=GetBValue(pix);
  26.       pix1=0.3*cr+0.6*cg+0.1*cb;
  27.       pix=RGB(pix1,pix1,pix1);
  28.       Image1->Picture->Bitmap->Canvas->Pixels[ii][jj]=(TColor)pix;
  29.     }
  30. }
  31. //---------------------------------------------------------------------------