"Try": draw a few lattice images and draw a few lattice images.

Source: Internet
Author: User

"Try": draw a few lattice images and draw a few lattice images.

This article is a personal attempt. The ultimate goal is to store offline data for Dot Matrix images.

This article only includes code for generating dot matrix images, not reading dot matrix images.

 

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 {18g. 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); 27g. 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 (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

Effect preview:

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.