Last active
June 6, 2018 22:03
-
-
Save PiotrWegrzyn/536617f086a26b1c71f89be1343fdee5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
namespace WindowsFormsApplication8 | |
{ | |
public partial class Form1 : Form | |
{ | |
private System.Drawing.Graphics g; | |
private System.Drawing.Pen pen1 = new System.Drawing.Pen(Color.Blue, 3); | |
Rectangle kwadrat, kwadrat2, kwadrat3, kwadrat4, kwadrat5, kwadrat6; | |
private void button2_Click(object sender, EventArgs e) | |
{ | |
Refresh(); | |
} | |
private void pictureBox1_MouseClick(object sender, MouseEventArgs e) | |
{ | |
Color pixel = bm.GetPixel(e.X, e.Y); | |
double c = 1 - (System.Convert.ToDouble(pixel.R) / 255); | |
double m = 1 - (System.Convert.ToDouble(pixel.G) / 255); | |
double y = 1 - (System.Convert.ToDouble(pixel.B) / 255); | |
//MessageBox.Show("RGB:" + System.Convert.ToString(pixel.R) + "," + System.Convert.ToString(pixel.G) + "," + System.Convert.ToString(pixel.B)); | |
textBox1.Text = "RGB:" + System.Convert.ToString(pixel.R) + "," + System.Convert.ToString(pixel.G) + "," + System.Convert.ToString(pixel.B); | |
textBox2.Text = "CMY:" + System.Convert.ToString(c) + "," + System.Convert.ToString(m) + "," + System.Convert.ToString(y); | |
double r = System.Convert.ToDouble(pixel.R); | |
double g = System.Convert.ToDouble(pixel.G); | |
double b = System.Convert.ToDouble(pixel.B); | |
double delta, min; | |
double h = 0, s, v; | |
min = Math.Min(Math.Min(r, g), b); | |
v = Math.Max(Math.Max(r, g), b); | |
delta = v - min; | |
if (v == 0.0) | |
s = 0; | |
else | |
s = delta / v; | |
if (s == 0) | |
h = 0.0; | |
else | |
{ | |
if (r == v) | |
h = (g - b) / delta; | |
else if (g == v) | |
h = 2 + (b - r) / delta; | |
else if (b == v) | |
h = 4 + (r - g) / delta; | |
h *= 60; | |
if (h < 0.0) | |
h = h + 360; | |
} | |
v /= 255; | |
textBox3.Text = "HSV:" + System.Convert.ToString(h) + "," + System.Convert.ToString(s) + "," + System.Convert.ToString(v); | |
} | |
Bitmap bm; | |
public Form1() | |
{ | |
InitializeComponent(); | |
// rysunek = Graphics.FromImage(pictureBox1.Image); | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
int x = pictureBox1.Width; | |
int y = pictureBox1.Height; | |
bm = new Bitmap(x, y); | |
Graphics gr = Graphics.FromImage(bm); | |
for (int i = 0; i < 101; i++) | |
{ | |
for (int j = 0; j < 101; j++) | |
{ | |
int u = (int)(i * 255.0 / 100); | |
int v = (int)(j * 255.0 / 100); | |
pen1.Color = Color.FromArgb(255 - u, 0, v); | |
gr.DrawRectangle(pen1, 0 + i, 0 + j, 1, 1); | |
// pictureBox1.Refresh(); | |
} | |
} | |
for (int i = 0; i < 101; i++) | |
{ | |
for | |
( | |
int | |
j = 0; j < 101; j++) | |
{ | |
int u = (int)(i * 255.0 / 100); | |
int v = (int)(j * 255.0 / 100); | |
pen1.Color = Color.FromArgb(255 - u, 0, v); | |
gr.DrawRectangle(pen1, 0 + i, 0 + j, 1, 1); | |
// pictureBox1.Refresh(); | |
} | |
} | |
for (int i = 0; i < 101; i++) | |
{ | |
for | |
( | |
int | |
j = 0; j < 101; j++) | |
{ | |
int u = (int)(i * 255.0 / 100); | |
int v = (int)(j * 255.0 / 100); | |
pen1.Color = Color.FromArgb(255 - u, 255, v); | |
gr.DrawRectangle(pen1, 101 + i, j, 1, 1); | |
// pictureBox1.Refresh(); | |
} | |
} | |
for (int i = 0; i < 101; i++) | |
{ | |
for | |
( | |
int | |
j = 0; j < 101; j++) | |
{ | |
int u = (int)(i * 255.0 / 100); | |
int v = (int)(j * 255.0 / 100); | |
pen1.Color = Color.FromArgb(255 - u, v, 0); | |
gr.DrawRectangle(pen1, 201 + i, j, 1, 1); | |
// pictureBox1.Refresh(); | |
} | |
} | |
for (int i = 0; i < 101; i++) | |
{ | |
for | |
( | |
int | |
j = 0; j < 101; j++) | |
{ | |
int u = (int)(i * 255.0 / 100); | |
int v = (int)(j * 255.0 / 100); | |
pen1.Color = Color.FromArgb(255 - u, v, 255); | |
gr.DrawRectangle(pen1, 301 + i, j, 1, 1); | |
// pictureBox1.Refresh(); | |
} | |
} | |
for (int i = 0; i < 101; i++) | |
{ | |
for | |
( | |
int | |
j = 0; j < 101; j++) | |
{ | |
int u = (int)(i * 255.0 / 100); | |
int v = (int)(j * 255.0 / 100); | |
pen1.Color = Color.FromArgb(u, 255 - v, 0); | |
gr.DrawRectangle(pen1, 401 + i, j, 1, 1); | |
// pictureBox1.Refresh(); | |
} | |
} | |
for (int i = 0; i < 101; i++) | |
{ | |
for | |
( | |
int | |
j = 0; j < 101; j++) | |
{ | |
int u = (int)(i * 255.0 / 100); | |
int v = (int)(j * 255.0 / 100); | |
pen1.Color = Color.FromArgb(u, 255 - v, 255); | |
gr.DrawRectangle(pen1, 501 + i, j, 1, 1); | |
// pictureBox1.Refresh(); | |
} | |
} | |
pictureBox1.Image = bm; | |
} | |
private void pictureBox1_Click(object sender, EventArgs e) | |
{ | |
} | |
private void trackBar1_Scroll(object sender, EventArgs e) | |
{ | |
Refresh(); | |
int x = pictureBox1.Width; | |
int y = pictureBox1.Height; | |
bm = new Bitmap(x, y); | |
Graphics gr = Graphics.FromImage(bm); | |
pictureBox1.BackColor = Color.FromArgb(trackBar1.Value, trackBar2.Value, trackBar3.Value); | |
} | |
private void trackBar2_Scroll_1(object sender, EventArgs e) | |
{ | |
Refresh(); | |
int x = pictureBox1.Width; | |
int y = pictureBox1.Height; | |
bm = new Bitmap(x, y); | |
Graphics gr = Graphics.FromImage(bm); | |
pictureBox1.BackColor = Color.FromArgb(trackBar1.Value, trackBar2.Value, trackBar3.Value); | |
} | |
private void trackBar3_Scroll_1(object sender, EventArgs e) | |
{ | |
Refresh(); | |
int x = pictureBox1.Width; | |
int y = pictureBox1.Height; | |
bm = new Bitmap(x, y); | |
Graphics gr = Graphics.FromImage(bm); | |
pictureBox1.BackColor = Color.FromArgb(trackBar1.Value, trackBar2.Value, trackBar3.Value); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment