• GDI绘制图像


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing.Drawing2D;
    
    namespace WPAPricture
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            Font var_Font = new Font("隶书", 12, FontStyle.Regular);
            Rectangle rect = new Rectangle(10, 10, 160, 160);//设置矩形位置大小
            private void button1_Click(object sender, EventArgs e)
            {
                int tem_Line = 0;//远的直径
                int circularity_W = 4;//画笔的粗细
                if (panel1.Width >= panel1.Height)
                {
                    tem_Line = panel1.Height;
                }
                else 
                {
                    tem_Line = panel1.Width;
                }
                //设置圆形的绘制区域
                rect = new Rectangle(circularity_W,circularity_W,tem_Line-circularity_W*2,tem_Line-circularity_W*2);
                //设置星号的样式
                Font Star = new Font("Arial",30,FontStyle.Regular);
                string Star_str = "★";
                //实例化画布
                Graphics g = this.panel1.CreateGraphics();
                //消除图形的锯齿
                g.SmoothingMode = SmoothingMode.AntiAlias;
                //以白色填充画布的背景颜色
                g.Clear(Color.White);
                //创建画笔(颜色,大小)
                Pen myPen = new Pen(Color.Red,circularity_W);
                //绘制椭圆(画笔,边界)
                g.DrawEllipse(myPen,rect);
                //实例化sizef的大小
                SizeF Var_Size = new SizeF(rect.Width,rect.Height);
                Var_Size = g.MeasureString(Star_str,Star);
                //画星型(字符串,样式,画笔,坐标)
                g.DrawString(Star_str,Star,myPen.Brush,new PointF((rect.Width/2F)+circularity_W-Var_Size.Width/2F,rect.Height/2F-Var_Size.Width/2F));
                //测量要绘制的字符串的大小
                Var_Size = g.MeasureString("公章",var_Font);
                //绘制字符串
                g.DrawString("公章", var_Font, myPen.Brush, new PointF((rect.Width / 2F) + circularity_W - Var_Size.Width / 2f, rect.Height / 2F + Var_Size.Height *2));
                string tempStr = "1234567890";
                int len = tempStr.Length;
                //设置文字的旋转角度
                float angle = 180 + (180 - len * 20) / 2;
                for (int i = 0; i < len;i++)
                {
                    //将制定的平移添加到g的变换矩阵前
                    g.TranslateTransform((tem_Line + circularity_W / 2) / 2, (tem_Line + circularity_W / 2) / 2);
                    //将指定的旋转用于G类的变换矩阵
                    g.RotateTransform(angle);
                    Brush myBrush = Brushes.Red;
                    g.DrawString(tempStr.Substring(i,1),var_Font,myBrush,60,0);
                    g.ResetTransform();
                    angle += 20;
                }
            }
        }
    }
    
  • 相关阅读:
    [杂谈]关于前端如何学习框架的一点牢骚
    【2018】面试复习大纲
    迟来的2017总结
    [转载并收藏]JavaScript 疲劳终极指南:我们行业的真相
    想做好产品,一定要成为自己产品的用户
    2017年个人提升计划
    Chrome新发现
    不要被所在的公司或企业绑架
    半夜不想睡有感
    2016年总结
  • 原文地址:https://www.cnblogs.com/JueXiaoQiang/p/6747924.html
Copyright © 2020-2023  润新知