Get Color Pixel on Image



#pragma once

namespace My28 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
///
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
///

public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
///
/// Clean up any resources being used.
///

~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::PictureBox^ PctGetColor;
protected:
protected:
protected:
private:
///
/// Required designer variable.
///

System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

void InitializeComponent(void)
{
this->PctGetColor = (gcnew System::Windows::Forms::PictureBox());
(cli::safe_cast
(this->PctGetColor))->BeginInit();
this->SuspendLayout();
//
// PctGetColor
//
this->PctGetColor->Location = System::Drawing::Point(316, 1);
this->PctGetColor->Name = L"PctGetColor";
this->PctGetColor->Size = System::Drawing::Size(60, 44);
this->PctGetColor->TabIndex = 0;
this->PctGetColor->TabStop = false;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(377, 322);
this->Controls->Add(this->PctGetColor);
this->Name = L"Form1";
this->Text = L"Form1";
this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::Form1_Paint);
this->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::Form1_MouseDown);
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
(cli::safe_cast
(this->PctGetColor))->EndInit();
this->ResumeLayout(false);
}
#pragma endregion
//Get Color Pixel on Image
Graphics^GetColor_Graphics;
Bitmap^GetColor_Bitmap;
Color KColor;
private: System::Void Form1_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
int cX;
int cY;
cX=e->X;
cY=e->Y;
if(e->Button==Windows::Forms::MouseButtons::Left)
{
KColor=GetColor_Bitmap->GetPixel(cX,cY);
PctGetColor->BackColor=KColor;
this->Text="Current X : "+cX+" Current Y : "+cY;
}
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
PctGetColor->BorderStyle=Windows::Forms::BorderStyle::Fixed3D;
}
private: System::Void Form1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
GetColor_Graphics=this->CreateGraphics();
GetColor_Bitmap=gcnew Bitmap("C:\\Flower.Bmp");
GetColor_Graphics->DrawImage(GetColor_Bitmap,0,0,400,400);
}
};
}