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;
            }
        }
    }
}

 

转载于:https://www.cnblogs.com/JueXiaoQiang/p/6747924.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值