Esempio n. 1
0
        public static void AddColorGradientDropDownItems(ToolStripItemCollection itemCollection, EventHandler onClick)
        {
            itemCollection.Clear();
            Array values = Enum.GetValues(typeof(ColorGradientEnum));

            foreach (ColorGradientEnum colorGradient in values)
            {
                Bitmap            bitmap   = GradientBitmap.GenerateBitmap16x16(colorGradient);                  // bitmap implements IDisposable
                ToolStripMenuItem menuItem = new ToolStripMenuItem(colorGradient.GetShowName(), bitmap, onClick) // menuItem implements IDisposable
                {
                    ImageScaling = ToolStripItemImageScaling.None,
                    Tag          = colorGradient
                };
                itemCollection.Add(menuItem);
            }
        }
Esempio n. 2
0
        private static Bitmap GenerateBitmap16x16(ColorGradientEnum gradient)
        {
            int    n = 16, m = 16;
            Bitmap bitmap = new Bitmap(n, m, PixelFormat.Format32bppArgb);

            float[,] values = new float[n, m];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    values[i, j] = ((float)i + (float)j) / (float)(n * m);
                }
            }
            GetMinMax(values, out float vMin, out float vMax);
            Rectangle rectangle = new Rectangle(0, 0, n, m);

            GradientBitmap.FromValues(bitmap, rectangle, (int i, int j) =>
            {
                float z = (values[i, j] - vMin) / (vMax - vMin);
                return(ColorUtilities.GetColor(z, gradient, false));
            });
            return(bitmap);
        }