彩虹条带的绘制

 

 

效果如下所示。绘制的原理请参考本作者转载的文章  彩虹图的绘制

 

 

     /// <summary>
        /// 彩虹条带
        /// 0, gray; 1 color;
        /// </summary>
        /// <param name="mode"></param>
        private void DrawControlPanel(int mode = 0)
        {
            Rectangle borderRect = new Rectangle(20, 50, 25, 256);
            //Rectangle tmpSegRect;
            LinearGradientBrush brush;
            float nEverySegLength, k_r, k_g, k_b;
            int[] arrHeightSeg;
            List<Color> lstColors;
            int iSeg, i_ros, gap_length;
            Color penBaseColor;
            Graphics g_img;

            
            _imgCtlPanel = new Bitmap(splitContainer1.Panel2.Width, splitContainer1.Panel2.Height-80);
            g_img = Graphics.FromImage(_imgCtlPanel);

            if (mode == 0)
            {
                //灰色亮度带
                brush = new LinearGradientBrush(borderRect, Color.White, Color.Black, LinearGradientMode.Vertical);//渐变画刷
                g_img.FillRectangle(brush, borderRect);

                // 边框
                Pen pen = new Pen(Color.FromArgb(10, 10, 10));
                g_img.DrawRectangle(pen, borderRect);
            }
            else
            {
                // 彩虹条带
                // 段的划分
                nEverySegLength = borderRect.Height / 6.0f;
                arrHeightSeg = new int[7];
                lstColors = new List<Color>(7);
                penBaseColor = new Color();

                for (iSeg = 0; iSeg < 7; iSeg++)
                    arrHeightSeg[iSeg] = (int)(nEverySegLength * iSeg + 0.5);
                lstColors.Add(Color.FromArgb(255, 0, 0));
                lstColors.Add(Color.FromArgb(255, 0, 255));
                lstColors.Add(Color.FromArgb(0, 0, 255));
                lstColors.Add(Color.FromArgb(0, 255, 255));
                lstColors.Add(Color.FromArgb(0, 255, 0));
                lstColors.Add(Color.FromArgb(255, 255, 0));
                lstColors.Add(Color.FromArgb(255, 0, 0));

                for (iSeg = 0; iSeg < 6; iSeg++)
                {
                    gap_length = arrHeightSeg[iSeg + 1] - arrHeightSeg[iSeg];
                    penBaseColor = lstColors[iSeg];

                    k_r = (lstColors[iSeg + 1].R - penBaseColor.R) / (float)gap_length;
                    k_g = (lstColors[iSeg + 1].G - penBaseColor.G) / (float)gap_length;
                    k_b = (lstColors[iSeg + 1].B - penBaseColor.B) / (float)gap_length;

                    for (i_ros = arrHeightSeg[iSeg]; i_ros < arrHeightSeg[iSeg + 1]; i_ros++)
                    {

                        g_img.DrawLine(
                            new Pen(new SolidBrush(Color.FromArgb(
                                Math.Min((int)(penBaseColor.R + k_r * (i_ros - arrHeightSeg[iSeg]) + 0.5), 255),
                                Math.Min((int)(penBaseColor.G + k_g * (i_ros - arrHeightSeg[iSeg]) + 0.5), 255),
                                Math.Min((int)(penBaseColor.B + k_b * (i_ros - arrHeightSeg[iSeg]) + 0.5), 255)))),
                            borderRect.Left, borderRect.Top + i_ros, borderRect.Right, borderRect.Top + i_ros);
                    }
                }
            }
            
            g_img.DrawString(string.Format("{0:f3}m",_dataTerrain.maxValue), new Font("宋体", 9), new SolidBrush(Color.Black), borderRect.Right + 8, borderRect.Top - 8);
            g_img.DrawString(string.Format("{0:f3}m", _dataTerrain.minValue), new Font("宋体", 9), new SolidBrush(Color.Black), borderRect.Right + 8, borderRect.Bottom - 8);
            g_img.Dispose();

            splitContainer1.Panel2.Invalidate() ;
            //g.DrawImage(_imgCtlPanel, new Rectangle(0, 0, _imgCtlPanel.Width, _imgCtlPanel.Height), 0.0f, 0.0f, _imgCtlPanel.Width, _imgCtlPanel.Height, GraphicsUnit.Pixel);


        }

 

posted @ 2017-06-14 21:33  wenglabs  阅读(301)  评论(0编辑  收藏  举报