Autor Beitrag
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4798
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: So 10.07.11 20:51 
Hallo,

such mal nach "C# HSV RGB" im Internet.

Hier im Forum habe ich dazu diesen Beitrag www.c-sharp-forum.de....php?p=628812#628812 gefunden.

P.S: bezogen auf deinen Screenshot: negative Farb- und Helligkeitswerte sind eher unüblich (normal von 0 bis 1 bzw. 0 bis 360 bzw. 0 bis 100)
Ansonsten sieht es aber schon sehr stylisch aus :zustimm:
BleachRukia
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 11.07.11 00:21 
Hallo TH69,

vielen vielen dank für den Link, werde in mir anschauen.

Habe beim Farbton MinWert = -180 und MaxWert = 180 und bei den anderen beiden, MinWert = -100 und Maxwert = 100.

Aber die Panels müssen immer die Breite von 200 haben, sonst klappt das nicht Werten :D

Liebe Grüße BleachRukia

Ps. Benutze diese ColorSlider nicht um eine eigene Farbe zu erstellen sondern die eines Bildes zu verändern :D
BleachRukia
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 11.07.11 01:52 
Hallo Leute,

habe jetzt einen ziemlich genialen Code für HSV zu RGB gefunden: stackoverflow.com/qu...m-api-for-hsv-to-rgb

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
        public static Color ColorFromHSV(double hue, double saturation, double value)
        {
            int hi = Convert.ToInt32(Math.Floor(hue / 60)) % 6;
            double f = hue / 60 - Math.Floor(hue / 60);

            value = value * 255;
            int v = Convert.ToInt32(value);
            int p = Convert.ToInt32(value * (1 - saturation));
            int q = Convert.ToInt32(value * (1 - f * saturation));
            int t = Convert.ToInt32(value * (1 - (1 - f) * saturation));

            if (hi == 0)
                return Color.FromArgb(255, v, t, p);
            else if (hi == 1)
                return Color.FromArgb(255, q, v, p);
            else if (hi == 2)
                return Color.FromArgb(255, p, v, t);
            else if (hi == 3)
                return Color.FromArgb(255, p, q, v);
            else if (hi == 4)
                return Color.FromArgb(255, t, p, v);
            else
                return Color.FromArgb(255, v, p, q);
        }


Nur leider ist jetzt mein Problem das ich einen Code gesucht habe für HSL zu RGB, also einfach nur das der V Wert bei HSV über 1 gehen kann um das Bild heller zu machen.

Kennt Jemand eine Lösung wie man den Code zu HSL umschreiben kann ?

Liebe Grüße BleachRukia
BleachRukia
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 11.07.11 17:23 
Hallo Leute,

habe jetzt leider nichts funktionierendes zum Thema HSL zu RGB gefunden, war jetzt auch nicht so wichtig gewesen, Photoshop macht das auch nur bei HSV, wenn es darum geht eigene Farben zu erstellen.

Aber die Frage zu diesem Thema ist eigentlich schon längst beantwortet :D

Hier mal der Code für die Color Sliders: (Die Panels müssen immer eine Breite von 200 haben)

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.Select();
        }

        int DrawPosition;
        Color Color01, Color02;
        private void HuePanel_Paint(object sender, PaintEventArgs e)
        {
            for (int i = 0; i < 6; i++)
            {
                switch (i)
                {
                    case 0:
                        Color01 = Color.Red;
                        Color02 = Color.Yellow;
                        break;
                    case 1:
                        Color01 = Color.Yellow;
                        Color02 = Color.Green;
                        break;
                    case 2:
                        Color01 = Color.Green;
                        Color02 = Color.Cyan;
                        break;
                    case 3:
                        Color01 = Color.Cyan;
                        Color02 = Color.Blue;
                        break;
                    case 4:
                        Color01 = Color.Blue;
                        Color02 = Color.Magenta;
                        break;
                    case 5:
                        Color01 = Color.Magenta;
                        Color02 = Color.Red;
                        break;
                }

                Rectangle Rectangle = new Rectangle(DrawPosition, 0this.HuePanel.Width / 6this.HuePanel.Height);
                LinearGradientBrush LinearGradientBrush = new LinearGradientBrush(Rectangle, Color01, Color02, LinearGradientMode.Horizontal);
                LinearGradientBrush.WrapMode = WrapMode.TileFlipX;
                e.Graphics.FillRectangle(LinearGradientBrush, Rectangle);
                DrawPosition += this.HuePanel.Width / 6;
            }
        }

        private void SaturationPanel_Paint(object sender, PaintEventArgs e)
        {
            Rectangle Rectangle = new Rectangle(00this.SaturationPanel.Width, this.SaturationPanel.Height);
            LinearGradientBrush LinearGradientBrush = new LinearGradientBrush(Rectangle, Color.White, Color.Red, LinearGradientMode.Horizontal);
            LinearGradientBrush.WrapMode = WrapMode.TileFlipX;
            e.Graphics.FillRectangle(LinearGradientBrush, Rectangle);
        }

        private void BrightnessPanel_Paint(object sender, PaintEventArgs e)
        {
            Rectangle Rectangle = new Rectangle(00this.BrightnessPanel.Width, this.BrightnessPanel.Height);
            LinearGradientBrush LinearGradientBrush = new LinearGradientBrush(Rectangle, Color.Black, Color.Red, LinearGradientMode.Horizontal);
            LinearGradientBrush.WrapMode = WrapMode.TileFlipX;
            e.Graphics.FillRectangle(LinearGradientBrush, Rectangle);
        }

        int HueArrow = 0;
        int SaturationArrow = 100;
        int BrightnessArrow = 0;
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Point[] HueTriangle = { new Point(this.HuePanel.Location.X + this.HuePanel.Width / 2 - 6 + HueArrow, this.HuePanel.Location.Y + this.HuePanel.Height + 10), 
                                 new Point(this.HuePanel.Location.X + this.HuePanel.Width / 2 + 6 + HueArrow, this.HuePanel.Location.Y + this.HuePanel.Height + 10), 
                                 new Point(this.HuePanel.Location.X + this.HuePanel.Width / 2 + HueArrow, this.HuePanel.Location.Y + this.HuePanel.Height) };
            e.Graphics.FillPolygon(new SolidBrush(Color.Gray), HueTriangle);

            Point[] SaturationTriangle = { new Point(this.SaturationPanel.Location.X - 6 + SaturationArrow, this.SaturationPanel.Location.Y + this.SaturationPanel.Height + 10), 
                                 new Point(this.SaturationPanel.Location.X + 6 + SaturationArrow, this.SaturationPanel.Location.Y + this.SaturationPanel.Height + 10), 
                                 new Point(this.SaturationPanel.Location.X + SaturationArrow, this.SaturationPanel.Location.Y + this.SaturationPanel.Height) };
            e.Graphics.FillPolygon(new SolidBrush(Color.Gray), SaturationTriangle);

            Point[] BrightnessTriangle = { new Point(this.BrightnessPanel.Location.X + this.BrightnessPanel.Width / 2 - 6 + BrightnessArrow, this.BrightnessPanel.Location.Y + this.BrightnessPanel.Height + 10), 
                                 new Point(this.BrightnessPanel.Location.X + this.BrightnessPanel.Width / 2 + 6 + BrightnessArrow, this.BrightnessPanel.Location.Y + this.BrightnessPanel.Height + 10), 
                                 new Point(this.BrightnessPanel.Location.X + this.BrightnessPanel.Width / 2 + BrightnessArrow, this.BrightnessPanel.Location.Y + this.BrightnessPanel.Height) };
            e.Graphics.FillPolygon(new SolidBrush(Color.Gray), BrightnessTriangle);
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (e.Y >= this.HuePanel.Location.Y + this.HuePanel.Height && e.Y <= this.HuePanel.Location.Y + this.HuePanel.Height + 10)
                {
                    if (e.X >= this.HuePanel.Location.X && e.X <= this.HuePanel.Location.X + this.HuePanel.Width)
                    {
                        HueArrow = e.X - this.HuePanel.Location.X - this.HuePanel.Width / 2;
                    }
                    else if (e.X <= this.HuePanel.Location.X)
                    {
                        HueArrow = -100;
                    }
                    else if (e.X >= this.HuePanel.Location.X + this.HuePanel.Width)
                    {
                        HueArrow = 100;
                    }

                    this.HueTextBox.Text = Convert.ToString(HueArrow * 18 / 10);
                }

                if (e.Y >= this.SaturationPanel.Location.Y + this.SaturationPanel.Height && e.Y <= this.SaturationPanel.Location.Y + this.SaturationPanel.Height + 10)
                {
                    if (e.X >= this.SaturationPanel.Location.X && e.X <= this.SaturationPanel.Location.X + this.SaturationPanel.Width)
                    {
                        SaturationArrow = e.X - this.SaturationPanel.Location.X;
                    }
                    else if (e.X <= this.SaturationPanel.Location.X)
                    {
                        SaturationArrow = 0;
                    }
                    else if (e.X >= this.SaturationPanel.Location.X + this.SaturationPanel.Width)
                    {
                        SaturationArrow = 200;
                    }

                    this.SaturationTextBox.Text = Convert.ToString(SaturationArrow - 100);
                }

                if (e.Y >= this.BrightnessPanel.Location.Y + this.BrightnessPanel.Height && e.Y <= this.BrightnessPanel.Location.Y + this.BrightnessPanel.Height + 10)
                {
                    if (e.X >= this.BrightnessPanel.Location.X && e.X <= this.BrightnessPanel.Location.X + this.BrightnessPanel.Width)
                    {
                        BrightnessArrow = e.X - this.BrightnessPanel.Location.X - this.BrightnessPanel.Width / 2;
                    }
                    else if (e.X <= this.SaturationPanel.Location.X)
                    {
                        BrightnessArrow = -100;
                    }
                    else if (e.X >= this.BrightnessPanel.Location.X + this.BrightnessPanel.Width)
                    {
                        BrightnessArrow = 100;
                    }

                    this.BrightnessTextBox.Text = Convert.ToString(BrightnessArrow);
                }

                this.Invalidate();
            }
        }

        private void HueTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (Convert.ToInt32(this.HueTextBox.Text) < -180)
                {
                    this.HueTextBox.Text = "-180";
                }
                else if (Convert.ToInt32(this.HueTextBox.Text) > 180)
                {
                    this.HueTextBox.Text = "180";
                }

                HueArrow = Convert.ToInt32(this.HueTextBox.Text) / 18 * 10;
                this.Invalidate();
            }
        }

        private void SaturationTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (Convert.ToInt32(this.SaturationTextBox.Text) < -100)
                {
                    this.SaturationTextBox.Text = "-100";
                }
                else if (Convert.ToInt32(this.SaturationTextBox.Text) > 100)
                {
                    this.SaturationTextBox.Text = "100";
                }

                SaturationArrow = Convert.ToInt32(this.SaturationTextBox.Text) + 100;
                this.Invalidate();
            }
        }

        private void BrightnessTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (Convert.ToInt32(this.BrightnessTextBox.Text) < -100)
                {
                    this.BrightnessTextBox.Text = "-100";
                }
                else if (Convert.ToInt32(this.BrightnessTextBox.Text) > 100)
                {
                    this.BrightnessTextBox.Text = "100";
                }

                BrightnessArrow = Convert.ToInt32(this.BrightnessTextBox.Text);
                this.Invalidate();
            }
        }
    }
}


Liebe Grüße BleachRukia