|
|
-
Start Borland C++ Builder with the startup form.
-
Right-click the desired picture above (I created
them using MS Image Composer) and save it to your hard disk where you
can retrieve it in the next step
-
On the form, add an Image control and set its
Picture property to the picture you saved
-
Design the rest of the form with a Panel control named
pnlColor, three Edit controls named edtRed, edtGreen, and edtBlue, and
a ColorDialog control:
-
Here is the header file of the form:
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Dialogs.hpp>
#include <ExtCtrls.hpp>
#include <jpeg.hpp>
#include <Graphics.hpp>
#include <Buttons.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TLabel *Label2;
TEdit *edtRed;
TLabel *Label3;
TEdit *edtGreen;
TLabel *Label4;
TEdit *edtBlue;
TColorDialog *ColorDialog1;
TPanel *pnlColor;
TImage *Image1;
TBitBtn *BitBtn1;
void __fastcall pnlColorDblClick(TObject *Sender);
void __fastcall BitBtn1Click(TObject *Sender);
void __fastcall Image1MouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall Image1MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall Image1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y);
private:
Boolean IsScanning; // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
|
-
Here is the source file of the form:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <Windows.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
IsScanning = False;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::pnlColorDblClick(TObject *Sender)
{
if( ColorDialog1->Execute() )
{
COLORREF Clr = ColorDialog1->Color;
pnlColor->Color = TColor(Clr);
edtRed->Text = GetRValue(Clr);
edtGreen->Text = GetGValue(Clr);
edtBlue->Text = GetBValue(Clr);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
IsScanning = True;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
IsScanning = False;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
if( IsScanning == True )
{
TColor Clr = Image1->Canvas->Pixels[X][Y];
edtRed->Text = GetRValue(Clr);
edtGreen->Text = GetGValue(Clr);
edtBlue->Text = GetBValue(Clr);
pnlColor->Color = Clr;
}
}
//---------------------------------------------------------------------------
|
-
Test the application
|
|
|