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

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::SplitColor(TCanvas *S_Cv,TCanvas *D_Cv,int width,int height,int nn)
  16. {
  17.   int ii,jj;
  18.   int rgb,rgb1,Rv,Gv,Bv,Cv,Mv,Yv,Kv;
  19.   for(ii=0;ii<height;ii++)
  20.   {
  21.     for(jj=0;jj<width;jj++)
  22.     {
  23.       rgb=S_Cv->Pixels[jj][ii];
  24.       Rv=GetRValue(rgb);
  25.       Gv=GetGValue(rgb);
  26.       Bv=GetBValue(rgb);
  27.       Cv=Rv;
  28.       Mv=Gv;
  29.       Yv=Bv;
  30.       if((Rv==Gv)&&(Gv==Bv))
  31.       {
  32.         Kv=Gv;Cv=255;Mv=255;Yv=255;
  33.       }
  34.       else Kv=255;
  35. //
  36.       if(nn==0)rgb1=Cv;
  37.       else if(nn==1)rgb1=Mv;
  38.       else if(nn==2)rgb1=Yv;
  39.       else     rgb1=Kv;
  40.       D_Cv->Pixels[jj][ii]=TColor(RGB(Byte(rgb1),Byte(rgb1),Byte(rgb1)));
  41.     }
  42.   }
  43. }
  44. //---------------------------------------------------------------------------
  45. void __fastcall TForm1::Button1Click(TObject *Sender)
  46. {
  47.   SplitColor(Image1->Canvas,Image2->Canvas,Image1->Width,Image1->Height,0);
  48.   SplitColor(Image1->Canvas,Image3->Canvas,Image1->Width,Image1->Height,1);
  49.   SplitColor(Image1->Canvas,Image4->Canvas,Image1->Width,Image1->Height,2);
  50.   SplitColor(Image1->Canvas,Image5->Canvas,Image1->Width,Image1->Height,3);
  51. }
  52. //---------------------------------------------------------------------------
  53. void __fastcall TForm1::Button2Click(TObject *Sender)
  54. {
  55.   SplitColor(Image6->Canvas,Image2->Canvas,Image1->Width,Image1->Height,0);
  56.   SplitColor(Image6->Canvas,Image3->Canvas,Image1->Width,Image1->Height,1);
  57.   SplitColor(Image6->Canvas,Image4->Canvas,Image1->Width,Image1->Height,2);
  58.   SplitColor(Image6->Canvas,Image5->Canvas,Image1->Width,Image1->Height,3);
  59. }
  60. //---------------------------------------------------------------------------