Rev 810 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 807 | chris | 1 | using System; |
| 2 | using System.Collections.Generic; |
||
| 3 | using System.ComponentModel; |
||
| 4 | using System.Drawing; |
||
| 5 | using System.Data; |
||
| 6 | using System.Linq; |
||
| 7 | using System.Text; |
||
| 8 | using System.Threading.Tasks; |
||
| 9 | using System.Windows.Forms; |
||
| 810 | chris | 10 | using System.Drawing.Imaging; |
| 807 | chris | 11 | |
| 810 | chris | 12 | using System.Runtime.InteropServices; |
| 13 | |||
| 807 | chris | 14 | namespace ColorPicker |
| 15 | { |
||
| 16 | public partial class ColorWidget: UserControl |
||
| 17 | { |
||
| 810 | chris | 18 | private Bitmap mGradientBox = null; |
| 19 | |||
| 807 | chris | 20 | public ColorWidget() |
| 21 | { |
||
| 22 | InitializeComponent(); |
||
| 810 | chris | 23 | |
| 24 | mGradientBox = new Bitmap(200, 200); |
||
| 25 | Rectangle rect = new Rectangle(0, 0, 200, 200); |
||
| 26 | BitmapData data = mGradientBox.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb); |
||
| 27 | |||
| 28 | IntPtr ptr = data.Scan0; |
||
| 29 | int bytes = data.Stride * mGradientBox.Height; |
||
| 30 | var rgbValues = new byte[bytes]; |
||
| 31 | |||
| 811 | chris | 32 | /*for (int i = 0; i < bytes; i++) |
| 810 | chris | 33 | { |
| 34 | rgbValues[i] = (byte)((i * 255) / (3 * bytes)); |
||
| 811 | chris | 35 | }*/ |
| 36 | |||
| 37 | int width = data.Stride / 3; |
||
| 38 | int height = mGradientBox.Height; |
||
| 39 | int i = 0; |
||
| 40 | |||
| 41 | float h = 0; |
||
| 42 | |||
| 43 | for (int x = 0; x < width; x++) |
||
| 44 | { |
||
| 45 | for (int y = 0; y < height; y++) |
||
| 46 | { |
||
| 47 | float s = (float)x / (float)width; |
||
| 48 | float v = (float)y / (float)height; |
||
| 49 | |||
| 50 | MathUtil |
||
| 51 | } |
||
| 810 | chris | 52 | } |
| 53 | |||
| 54 | Marshal.Copy(rgbValues, 0, ptr, bytes); |
||
| 55 | |||
| 56 | mGradientBox.UnlockBits(data); |
||
| 807 | chris | 57 | } |
| 809 | chris | 58 | |
| 59 | private void colorWheelBox_Paint(object sender, PaintEventArgs e) |
||
| 60 | { |
||
| 61 | Graphics g = e.Graphics; |
||
| 62 | |||
| 63 | g.DrawString("This is a diagonal line drawn on the control", new Font("Arial", 10), System.Drawing.Brushes.Blue, new Point(30, 30)); |
||
| 64 | |||
| 65 | g.DrawLine(System.Drawing.Pens.Red, colorWheelBox.Left, colorWheelBox.Top, colorWheelBox.Right, colorWheelBox.Bottom); |
||
| 810 | chris | 66 | |
| 67 | Rectangle rect = new Rectangle(10, 10, Width - 20, Height - 20); |
||
| 68 | |||
| 69 | g.DrawImage(mGradientBox, rect); |
||
| 809 | chris | 70 | } |
| 807 | chris | 71 | } |
| 72 | } |