zoukankan      html  css  js  c++  java
  • WinForm画图

    简单的画图

    关键代码

    /// <summary>
            /// 生成图片
            /// </summary>
            /// <param name="imgWidth">图片的宽</param>
            /// <param name="imgHeight">图片的高</param>
            /// <param name="leftPercent">左图占百分比</param>
            /// <param name="rightPercent">右图占百分比</param>
            /// <param name="percent">图片文本</param>
            /// <returns></returns>
            private Image DrawMultyProcessBar(int imgWidth, int imgHeight, float leftPercent, float rightPercent, float percent)
            {
                if (imgWidth <= 0 || imgHeight <= 0)
                    throw new Exception("参数imgWidth必须大于0,参数imgHeight必须大于0");
    
                if(leftPercent>1 || rightPercent>1)
                    throw new Exception("参数leftPercent必须小于1,参数rightPercent必须小于1");
    
                if (leftPercent + rightPercent != 1.0)
                    throw new Exception("参数leftPercent+rightPercent必须等于1");
    
                string str = percent.ToString() + "%";
                Bitmap bmp = new Bitmap(imgWidth, imgHeight);
                Graphics grp = Graphics.FromImage(bmp);
    
                grp.FillRectangle(SystemBrushes.HotTrack, new Rectangle(0, 0, (int)(leftPercent * imgWidth), imgHeight));
                grp.FillRectangle(SystemBrushes.Highlight, new Rectangle((int)(leftPercent * imgWidth), 0, (int)(rightPercent * imgWidth), imgHeight));
    
                PointF point = new PointF(bmp.Width / 2 - str.Length * 9 / 2, bmp.Height / 2 - 9 / 2);
                grp.DrawString(str, new Font(new FontFamily("宋体"), 9), Brushes.White, point);
                grp.Dispose();
    
                return bmp;
            }
    

     调用部分关键代码

    pictureBox1.Image = DrawMultyProcessBar(pictureBox1.Width, pictureBox1.Height, 0.5f, 0.5f, 50.0f);
    
  • 相关阅读:
    认识目标文件的内容
    PetaLinux工程更新HDF文件的脚本
    [海思] 中断申请和重启问题
    [海思] HI3531D串口调试
    【C语言】结构体初始化
    [ZCU106] Petalinux 2018.3 与启动环境搭建记录
    旧版本源码usbip的移植
    jar包下载地址
    Django框架
    前端内容
  • 原文地址:https://www.cnblogs.com/jzblogs/p/5736544.html
Copyright © 2011-2022 走看看