home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 July / DPPCPRO0799.ISO / RWC / Code / VisProg.exe / UGray.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-11  |  1.4 KB  |  39 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "UGray.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma resource "*.dfm"
  9. TForm1 *Form1;
  10. //---------------------------------------------------------------------------
  11. __fastcall TForm1::TForm1(TComponent* Owner)
  12.         : TForm(Owner)
  13. {
  14. }
  15. //---------------------------------------------------------------------------
  16.  
  17. void __fastcall TForm1::OpenClick(TObject *Sender)
  18. {
  19.     if (OpenDialog->Execute()) Image1->Picture->LoadFromFile (OpenDialog->FileName);
  20. }
  21. //---------------------------------------------------------------------------
  22. void __fastcall TForm1::GrayScaleClick(TObject *Sender)
  23. {
  24.     Image1->Picture->Bitmap->PixelFormat = pf32bit;
  25.     for (int Row = 0; Row < Image1->Picture->Height; Row++) {
  26.         RGBQUAD * p = (RGBQUAD *) Image1->Picture->Bitmap->ScanLine [Row];
  27.         for (int Col = 0; Col < Image1->Picture->Width; Col++) {
  28.             int Brightness = p->rgbRed + p->rgbGreen + p->rgbBlue;
  29.             p->rgbRed = Brightness / 3;
  30.             p->rgbGreen = p->rgbRed;
  31.             p->rgbBlue = p->rgbRed;
  32.             p++;
  33.         }
  34.     }
  35.  
  36.     Image1->Invalidate();
  37. }
  38. //---------------------------------------------------------------------------
  39.