C # color extraction program

Source: Internet
Author: User

Using system;
Using system. diagnostics;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Using bitmaptest. properties;

Namespace bitmaptest
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}

Bitmap mybitmap;
Int cmd = 0;

Private void form1_load (Object sender, eventargs E)
{
Picturebox1.image = resources. bfq0002;
Mybitmap = (Bitmap) picturebox1.image;
}
/// <Summary>
/// Color (MOVE)
/// </Summary>
Private void picturebox#mousemove (Object sender, mouseeventargs E)
{
Int mousex = E. X;
Int Mousey = E. Y;
Txtpoint. Text = "(" + mousex + "," + Mousey + ")";
If (rbtmutil. Checked)
{
// Color
Try
{
Color pixelcolor = mybitmap. getpixel (mousex, Mousey );
Colorbox. backcolor = pixelcolor;
Txtcolorvalue. Text = system. Drawing. colortranslator. tohtml (pixelcolor );
}
Catch
{}
}

// Command
Switch (CMD)
{
Case 1: // draw a line
Solidbrush pixelbrush = new solidbrush (color. Red );
Graphics G = graphics. fromimage (mybitmap );
G. fillrectangle (pixelbrush, mousex, Mousey, 2, 2 );
Picturebox1.image = mybitmap;
Break;
Case 2:
Break;
Default:
Break;
}
}
/// <Summary>
/// Paint brush
/// </Summary>
Private void btnpen#click (Object sender, eventargs E)
{
If (cmd = 1)
{
Cmd = 0;
Btnpen1.image = resources.png _05252;
This. tooltip1.settooltip (this. btnpen1, "click to use paint brush ");
}
Else
{
Cmd = 1;
Btnpen1.image = resources.png _05253;
This. tooltip1.settooltip (this. btnpen1, "click to disable the paint brush ");
}
}
/// <Summary>
/// Restore
/// </Summary>
Private void button#click (Object sender, eventargs E)
{
Picturebox1.image = resources. bfq0002;
Mybitmap = (Bitmap) picturebox1.image;
}
/// <Summary>
/// Select the mouse color (click)
/// </Summary>
Private void picturebox#mousedown (Object sender, mouseeventargs E)
{
// Color
Try
{
Color pixelcolor = mybitmap. getpixel (E. X, E. y );
Colorbox. backcolor = pixelcolor;
Txtcolorvalue. Text = system. Drawing. colortranslator. tohtml (pixelcolor );
}
Catch
{}
}

}
}

By: http://www.cnblogs.com/tuyile006/archive/2008/03/07/1094359.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.