zoukankan      html  css  js  c++  java
  • 『尝试』随手绘制几张点阵图片

    本文仅属 个人尝试,最终目的是实现 点阵图片 存储离线数据。

    本文只包括 生成 点阵图片的代码,不包括 读取点阵图片。

     1     class Program
     2     {
     3         static void Main(string[] args)
     4         {
     5             
     6             int xp = 200;
     7             int yp = 55;
     8 
     9             for (int s = 3; s < 8; s++)
    10             {
    11                 int width = xp * s + (xp - 1);
    12                 int height = yp * s + (yp - 1);
    13 
    14                 using (Bitmap bitmap = new Bitmap(width, height))
    15                 {
    16                     using (Graphics g = Graphics.FromImage(bitmap))
    17                     {
    18                         g.Clear(Color.White);
    19 
    20                         for (int x = 0; x < xp; x++)
    21                             for (int y = 0; y < yp; y++)
    22                             {
    23                                 int px = x * (s + 1);
    24                                 int py = y * (s + 1);
    25 
    26                                 //g.FillRectangle(new SolidBrush(RandomColor()), px, py, s, s);
    27                                 g.FillPath(new SolidBrush(RandomColor()), GraphicsPath(px, py, s, s));
    28                             }
    29                     }
    30                     bitmap.Save(@"D:" + s + ".png", ImageFormat.Png);
    31                 }
    32             }
    33 
    34 
    35         }
    36 
    37 
    38         public static Color RandomColor()
    39         {
    40             int r = new Random(Guid.NewGuid().GetHashCode()).Next(2);
    41             int g = new Random(Guid.NewGuid().GetHashCode()).Next(2);
    42             int b = new Random(Guid.NewGuid().GetHashCode()).Next(2);
    43 
    44             return Color.FromArgb(r * 255, g * 255, b * 255);
    45         }
    46 
    47         public static GraphicsPath GraphicsPath(int px, int py, int pw, int ph)
    48         {
    49             GraphicsPath path = new GraphicsPath();
    50             path.StartFigure();
    51             path.AddLines(new Point[]{
    52                 new Point(px+1, py),
    53                 new Point(px+pw-1, py),
    54                 new Point(px+pw, py+1),
    55                 new Point(px+pw, py+ph-2),
    56                 new Point(px+pw-2, py+ph),
    57                 new Point(px+1, py+ph),
    58                 new Point(px, py+ph-2),
    59                 new Point(px, py+1)
    60             });
    61 
    62 
    63 
    64             //path.AddArc(new Rectangle(new Point(rect.X, rect.Y), new Size(2 * cRadius, 2 * cRadius)), 180, 90);
    65             //path.AddLine(new Point(rect.X + cRadius, rect.Y), new Point(rect.Right - cRadius, rect.Y));
    66             //path.AddArc(new Rectangle(new Point(rect.Right - 2 * cRadius, rect.Y), new Size(2 * cRadius, 2 * cRadius)), 270, 90);
    67             //path.AddLine(new Point(rect.Right, rect.Y + cRadius), new Point(rect.Right, rect.Bottom - cRadius));
    68             //path.AddArc(new Rectangle(new Point(rect.Right - 2 * cRadius, rect.Bottom - 2 * cRadius), new Size(2 * cRadius, 2 * cRadius)), 0, 90);
    69             //path.AddLine(new Point(rect.Right - cRadius, rect.Bottom), new Point(rect.X + cRadius, rect.Bottom));
    70             //path.AddArc(new Rectangle(new Point(rect.X, rect.Bottom - 2 * cRadius), new Size(2 * cRadius, 2 * cRadius)), 90, 90);
    71             //path.AddLine(new Point(rect.X, rect.Bottom - cRadius), new Point(rect.X, rect.Y + cRadius));
    72             path.CloseFigure();
    73             return path;
    74         }
    75 
    76     }
    View Code

    效果预览:

  • 相关阅读:
    安装Sql Server 2008 错误:the folder "c:\temp\sql2008_fullsp3_standard\pcu" you specified is not for pcusource input setting. Specify a valid folder.
    Log4Net error: Inheritance security rules violated while overriding member: 'log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData.....
    Java成长路线
    项目开发之故事经典:教授的裤子分析
    书籍的未来数字化革命的产物:电子书
    如何访问我的博客
    ComboBox应该如何绑定数据
    C#中的常用关键字
    如何编写优秀软件
    为什么现在都用面向对象开发,为什么现在都用分层开发结构?
  • 原文地址:https://www.cnblogs.com/shuxiaolong/p/20171122_001.html
Copyright © 2011-2022 走看看