C#绘制中国国旗的方法

本文实例讲述了C#绘制中国国旗的方法。分享给大家供大家参考。具体如下:

程序运行截图:

中国国旗被定义在《GB:12982-2004》中,以下是从维基百科条目中华人民共和国国旗中截的一张图,标出了五颗星大致的位置。

建立一个空的C# Windows窗体应用程序,窗体取名FormMain,在窗体中放一个PictureBox,取名为picFlagOfChina,并将Dock属性设置为Fill。程序代码中用到了窗体事件Load和Resize,程序代码如下:

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;
namespace ChineseFlag
{
 public partial class FormMain : Form
 {
  public FormMain()
  {
   InitializeComponent();
  }
  private void FormMain_Load(object sender, EventArgs e)
  {
   PaintFlag();
  }
  //修改窗体大小时发生
  private void FormMain_Resize(object sender, EventArgs e)
  {
   PaintFlag();
  }
  /// <summary>
  /// 在图片框 picFlagOfChina 中绘制国旗
  /// </summary>
  private void PaintFlag()
  {
   picFlagOfChina.BackColor = Color.Red;
   picFlagOfChina.Image = new Bitmap(
    picFlagOfChina.Width, picFlagOfChina.Height);
   Graphics g = Graphics.FromImage(picFlagOfChina.Image);
   Point[] p = new Point[] { };
   p = PentacleA(this.Width, this.Height);
   g.FillPolygon(Brushes.Yellow, p);
   p = PentacleB(this.Width, this.Height);
   g.FillPolygon(Brushes.Yellow, p);
   p = PentacleC(this.Width, this.Height);
   g.FillPolygon(Brushes.Yellow, p);
   p = PentacleD(this.Width, this.Height);
   g.FillPolygon(Brushes.Yellow, p);
   p = PentacleE(this.Width, this.Height);
   g.FillPolygon(Brushes.Yellow, p);
  }
  //大星
  private Point[] PentacleA(int width, int height)
  {
   return new Point[]
   {
    new Point((int)(width / 30.0 * 5), (int)(height / 20.0 * 2)),
    new Point((int)(width / 30.0 * 5.7), (int)(height / 20.0 * 4.1)),
    new Point((int)(width / 30.0 * 8), (int)(height / 20.0 * 4.1)),
    new Point((int)(width / 30.0 * 6), (int)(height / 20.0 * 5.3)),
    new Point((int)(width / 30.0 * 6.8), (int)(height / 20.0 * 7.3)),
    new Point((int)(width / 30.0 * 5), (int)(height / 20.0 * 6.1)),
    new Point((int)(width / 30.0 * 3.2), (int)(height / 20.0 * 7.3)),
    new Point((int)(width / 30.0 * 4), (int)(height / 20.0 * 5.3)),
    new Point((int)(width / 30.0 * 2), (int)(height / 20.0 * 4.1)),
    new Point((int)(width / 30.0 * 4.3), (int)(height / 20.0 * 4.1)),
   };
  }
  //工人星
  private Point[] PentacleB(int width, int height)
  {
   return new Point[]
   {
    new Point((int)(width / 30.0 * 9.2), (int)(height / 20.0 * 2.5)),
    new Point((int)(width / 30.0 * 9.6), (int)(height / 20.0 * 2)),
    new Point((int)(width / 30.0 * 9.3), (int)(height / 20.0 * 1.4)),
    new Point((int)(width / 30.0 * 9.95), (int)(height / 20.0 * 1.7)),
    new Point((int)(width / 30.0 * 10.45), (int)(height / 20.0 * 1.1)),
    new Point((int)(width / 30.0 * 10.36), (int)(height / 20.0 * 1.85)),
    new Point((int)(width / 30.0 * 11), (int)(height / 20.0 * 2.1)),
    new Point((int)(width / 30.0 * 10.34), (int)(height / 20.0 * 2.25)),
    new Point((int)(width / 30.0 * 10.3), (int)(height / 20.0 * 2.95)),
    new Point((int)(width / 30.0 * 9.9), (int)(height / 20.0 * 2.3))
   };
  }
  //农民星
  private Point[] PentacleC(int width, int height)
  {
   return new Point[]
   {
    new Point((int)(width / 30.0 * 11), (int)(height / 20.0 * 4.1)),
    new Point((int)(width / 30.0 * 11.65), (int)(height / 20.0 * 3.8)),
    new Point((int)(width / 30.0 * 11.55), (int)(height / 20.0 * 3.05)),
    new Point((int)(width / 30.0 * 12.05), (int)(height / 20.0 * 3.6)),
    new Point((int)(width / 30.0 * 12.7), (int)(height / 20.0 * 3.3)),
    new Point((int)(width / 30.0 * 12.35), (int)(height / 20.0 * 3.98)),
    new Point((int)(width / 30.0 * 12.9), (int)(height / 20.0 * 4.5)),
    new Point((int)(width / 30.0 * 12.1), (int)(height / 20.0 * 4.3)),
    new Point((int)(width / 30.0 * 11.8), (int)(height / 20.0 * 5)),
    new Point((int)(width / 30.0 * 11.7), (int)(height / 20.0 * 4.2))
   };
  }
  //小资星
  private Point[] PentacleD(int width, int height)
  {
   return new Point[]
   {
    new Point((int)(width / 30.0 * 11.1), (int)(height / 20.0 * 6.7)),
    new Point((int)(width / 30.0 * 11.8), (int)(height / 20.0 * 6.7)),
    new Point((int)(width / 30.0 * 12), (int)(height / 20.0 * 6)),
    new Point((int)(width / 30.0 * 12.2), (int)(height / 20.0 * 6.7)),
    new Point((int)(width / 30.0 * 12.9), (int)(height / 20.0 * 6.7)),
    new Point((int)(width / 30.0 * 12.35), (int)(height / 20.0 * 7.1)),
    new Point((int)(width / 30.0 * 12.55), (int)(height / 20.0 * 7.8)),
    new Point((int)(width / 30.0 * 12), (int)(height / 20.0 * 7.4)),
    new Point((int)(width / 30.0 * 11.45), (int)(height / 20.0 * 7.8)),
    new Point((int)(width / 30.0 * 11.65), (int)(height / 20.0 * 7.1))
   };
  }
  //民资星(工人星向下平移7个单位)
  private Point[] PentacleE(int width, int height)
  {
   return new Point[]
   {
    new Point((int)(width / 30.0 * 9.2), (int)(height / 20.0 * 9.5)),
    new Point((int)(width / 30.0 * 9.6), (int)(height / 20.0 * 9)),
    new Point((int)(width / 30.0 * 9.3), (int)(height / 20.0 * 8.4)),
    new Point((int)(width / 30.0 * 9.95), (int)(height / 20.0 * 8.7)),
    new Point((int)(width / 30.0 * 10.45), (int)(height / 20.0 * 8.1)),
    new Point((int)(width / 30.0 * 10.36), (int)(height / 20.0 * 8.85)),
    new Point((int)(width / 30.0 * 11), (int)(height / 20.0 * 9.1)),
    new Point((int)(width / 30.0 * 10.34), (int)(height / 20.0 * 9.25)),
    new Point((int)(width / 30.0 * 10.3), (int)(height / 20.0 * 9.95)),
    new Point((int)(width / 30.0 * 9.9), (int)(height / 20.0 * 9.3))
   };
  }
 }
}

希望本文所述对大家的C#程序设计有所帮助。

(0)

相关推荐

  • C#绘制曲线图的方法

    本文实例讲述了C#绘制曲线图的方法.分享给大家供大家参考.具体如下: 1. 曲线图效果: 2. C#代码: /// <summary> /// 自动根据参数调整图像大小 /// </summary> public void Fit() { //计算字体距离 intFontSpace = FontSize + 5; //计算图像边距 float fltSpace = Math.Min(Width / 6, Height / 6); XSpace = fltSpace; YSpace

  • C#绘制椭圆的方法

    本文实例讲述了C#绘制椭圆的方法.分享给大家供大家参考.具体实现方法如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication2 { public partial

  • C#实现绘制浮雕图片效果实例

    本文采用C#实例讲解了处理图片为浮雕效果的实现方法,这在PS中是一个常见的功能,也是C#中的一个简单的图像处理例子.程序先读取原图,然后依次访问每个像素的RGB值,获取相邻两个像素的R.G.B值,计算与左上角像素的RGB分量之差,将计算后的RGB值回写到位图,最后进行图片的浮雕处理. 主要代码如下: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using Sy

  • C# 绘制统计图大全(柱状图, 折线图, 扇形图)

    统计图形种类繁多, 有柱状图, 折线图, 扇形图等等, 而统计图形的绘制方法也有很多, 有Flash制作的统计图形, 有水晶报表生成统计图形, 有专门制图软件制作, 也有编程语言自己制作的:这里我们用就C# 制作三款最经典的统计图: 柱状图, 折线图和扇形图:既然是统计, 当然需要数据, 这里演示的数据存于Sql Server2000中, 三款统计图形都是动态生成. 其中柱状图我会附上制作步骤, 其他两款统计图直接附源码. 说明: 需求不一样, 统计图形绘制后的显示效果也不一样, 比如这里柱状图

  • C#实现在图像中绘制文字图形的方法

    本文实例讲述了C#实现在图像中绘制文字图形的方法.分享给大家供大家参考.具体实现方法如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Drawing.Drawing2D; using S

  • C#利用GDI绘制常见图形和文字

    废话不多说,我们先来认识一下这个GDI+,看看它到底长什么样. GDI+:Graphics Device Interface Plus也就是图形设备接口,提供了各种丰富的图形图像处理功能;在C#.NET中,使用GDI+处理二维(2D)的图形和图像,使用DirectX处理三维(3D)的图形图像,图形图像处理用到的主要命名空间是System . Drawing:提供了对GDI+基本图形功能的访问,主要有Graphics类.Bitmap类.从Brush类继承的类.Font类.Icon类.Image类.

  • C#实现绘制面形图表的方法详解

    本例详细讲述了C#实现的面形图绘制例子,这是其中一个核心绘制文件的代码,代码中的里面的注释很多,也比较详细,相信对于初学者学习及理解C#图形绘制方面的技术要点.难点有所帮助. C#绘制面形图的主要功能代码如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using S

  • C#绘制飞行棋地图小程序

    1. 初始化地图,在绘制时可先将地图进行初始化,用数组来存储关卡的位置,然后利用循环给地图中 关卡所在处赋予代表关卡的值. 关键代码如下 /// <summary> /// 初始化游戏地图 /// </summary> static void InitialMap() { for (int i=0;i<Map.Length;i++) { Map[i] =0; } //用于存储关卡位置 int[] luckyTurn = { 6, 23, 40, 55, 69, 83,98 }

  • C#绘制中国国旗的方法

    本文实例讲述了C#绘制中国国旗的方法.分享给大家供大家参考.具体如下: 程序运行截图: 中国国旗被定义在<GB:12982-2004>中,以下是从维基百科条目中华人民共和国国旗中截的一张图,标出了五颗星大致的位置. 建立一个空的C# Windows窗体应用程序,窗体取名FormMain,在窗体中放一个PictureBox,取名为picFlagOfChina,并将Dock属性设置为Fill.程序代码中用到了窗体事件Load和Resize,程序代码如下: using System; using S

  • Python使用Turtle模块绘制国旗的方法示例

    turtle模块 turtle模块:python内置的绘图工具 turtle(海龟)模块,我们是用它来进行画图的,基本上就是画简单的直线,点,和曲线. 你可以把它想成一个小海龟,在沙滩上行走,然后留下的各种痕迹,使用Turtle模块可以绘制很多精美的图形. 基本操作(Turtle方法) turtle.forward(step):前进step个像素 turtle.back(step):后退step个像素 turtle.right():右转一个角度 turtle.left():左转一个角度 turt

  • Python和Perl绘制中国北京跑步地图的方法

    当你在一个城市,穿越大街小巷,跑步跑了几千公里之后,一个显而易见的想法是,我到底和之前比快了多少,跑量有何变化,如果能把在这个城市的所有路线全部画出来,会是怎样的景象呢? 1.数据来源:益动GPS 文章代码比较多,为了不吊人胃口,先看看最终效果: [/code] 首先需要有原始数据信息,手机上众多跑步软件提供了详细的记录,但它们共同的问题是不允许自由导入导出(可能是为了用户粘性吧).因此有一块智能运动手表应该是不二之选.我的是Garmin Fenix3,推荐一下: 益动GPS算是业界良心了,能够

  • vue+vuex+axios+echarts画一个动态更新的中国地图的方法

    本文介绍了vue+vuex+axios+echarts画一个动态更新的中国地图的方法,分享给大家,具体如下: 一. 生成项目及安装插件 # 安装vue-cli npm install vue-cli -g # 初始化项目 vue init webpack china-map # 切到目录下 cd china-map # 安装项目依赖 npm install # 安装 vuex npm install vuex --save # 安装 axios npm install axios --save

  • 在Vue中使用highCharts绘制3d饼图的方法

    highcharts是国外知名基于javascript的图表库.由于中文官网的vue中使用highcharts配置繁琐并且需要引入jquery作为依赖,所以弃用. 接下来,给各位伙伴简要的讲叙下highcharts在vue中的使用和配置方法. 首先使用 npm在你的项目中安装vue-highcharts npm install vue-highcharts --save 由于vue-highcharts依赖于highcharts,我们还需要安装后者 npm install highcharts

  • c# 绘制中国象棋棋盘与棋子

    本文是利用C# 实现中国象棋的棋盘绘制,以及初始化布局,并不实现中国象棋的对弈逻辑.仅供学习参考使用. 思路: 绘制中国象棋棋盘,竖线九条,横线十条.再中间绘制'楚河','汉界' . 绘制棋子,然后将棋子布局在棋盘上即可. 涉及知识点: 用户控件:用于实现棋盘的绘制,重写 OnPaint(PaintEventArgs e) 方法. Matrix:封装表示几何变换的 3x3 仿射矩阵.本例中主要用于旋转绘制反方的'汉界'. GraphicsPath:表示一系列相互连接的直线和曲线.本例中主要用于绘

  • js+html5实现canvas绘制网页时钟的方法

    本文实例讲述了js+html5实现canvas绘制网页时钟的方法,画的是一个可用于网页的.带摆的钟表,可以通过按钮调整其大小和位置,具体实现内容如下 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Clock</title> <script type="tex

  • 利用matplotlib+numpy绘制多种绘图的方法实例

    前言 matplotlib 是Python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地进行制图.本文将以例子的形式分析matplot中支持的,分析中常用的几种图.其中包括填充图.散点图(scatter plots).. 条形图(bar plots).等高线图(contour plots). 点阵图和3D图,下面来一起看看详细的介绍: 一.填充图 参考代码 from matplotlib.pyplot import * x=linspace(-3,3,100) y

  • jsp实现生成中国国旗图片效果代码

    本文实例讲述了jsp实现生成中国国旗图片效果代码.分享给大家供大家参考,具体如下: 图片截图如下: 具体代码如下: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page contentType="image/jpeg" import="java.awt.*, java.awt.image.*,jav

  • js+html5实现canvas绘制简单矩形的方法

    本文实例讲述了js+html5实现canvas绘制简单矩形的方法.分享给大家供大家参考.具体实现方法如下: <!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="200" height="100" style="border:1px solid #c3c3c3;"> Your browser does not sup

随机推荐