Recently began to learn the image processing this piece, learn a little bit, and so on after writing a small software ~
Here is: To draw the official seal.
#region Draw the official seal private void simplebutton_ to draw the official seal _click (object sender, EventArgs e) {int tem_line = 0; The diameter of the circle int circularity_w = 5; The thickness of the brush string star_str = "★"; Star Font star_font = new Font ("Arial", "fontstyle.regular");//Set the font style of the asterisk #region draw a circle if (Panel_ to draw the official seal.) Height > Panel_ to draw the official seal. width)//If the height of the Panel control is greater than or equal to width {tem_line = Panel_ the seal is drawn. Width; Sets the diameter of the width to circle} else {tem_line = Panel_ to draw the official seal. Height; Set height to circle diameter}//Set the drawing area of the Circle = = Now the area of the square rect = new Rectangle (Circularity_w, Circularity_w, Tem_line-2 * Circularity_w, tem_line-2 * circularity_w); Add: Graphics must have a vector, that is, where to draw//so must be this. CreateGraphics or panel. CreateGraphics and other format Graphics g = Panel_ to draw the official seal. CreateGraphics ();//Instantiate the Graphics class//eliminate the jagged g.smoothingmode of the drawing graph = Smoothingmode.antialias; System.Drawing.Drawing2D; G.clear (Color.White); Empties the background of the Panel1 control with white, preventing duplicate pen mypen = new Pen (color.red, Circularity_w); Sets the brush (color and thickness) g.drawellipse (mypen, rect); Draw a circle #endregion #region draw a star SizeF var_size = new SizeF (rect. Width, Rect. Height); Instantiate SizeF class var_size = G.measurestring (Star_str, Star_font); The specified string is measured//the position of the middle is drawn by the asterisk float star_x = (rect. WIDTH/2F) + circularity_w-var_size.width/2f; float star_y = rect. height/2f-var_size.width/2f; g.DrawString (Star_str, Star_font, Mypen.brush, New PointF (star_x, star_y)); #endregion #region Draw Text var_size = g.measurestring ("I special chapter", Var_font);//measure the specified string//Draw text: In the middle, but under the stars float m = (rect. WIDTH/2F) + circularity_w-var_size.width/2f; float n = rect. HEIGHT/2F + var_size.height * 2; g.DrawString ("I dedicated chapter", Var_Font, Mypen.brush, New PointF (M, n)); int len = 0; if (inputwords! = null)//If no text is entered, add the judgment {len = inputwords.length;//to get the length of the string} float angle = 180;//Sets the initial rotation angle of the text float change = 0; if (len > 1)//A Word requires special handling {change = len-1/(n/a); } for (int i = 0; i < len; i++)//The text is drawn in the specified radians {if (len > 1) { Equivalent to moving the coordinate system to the center of float x = (tem_line + CIRCULARITY_W/2)/2; Float y = (tem_line + CIRCULARITY_W/2)/2; Adds the specified translation to the transformation matrix of G before G.translatetransform (x, y); G.rotatetransform (angle);//convert the specified rotation to the transformation matrix of g brush MyBrush = brushes.red;//Define brush//Need Note that the position of the text at this point is based on the new coordinate system of the float words_x = TEM_LINE/2-6 * CIRCULARITY_W; float words_y = 0; g.DrawString (Inputwords.substring (i, 1), Var_font, MyBrush, words_x, words_y);//Display rotated text G.resettransform ();//Reset the Global transformation matrix of G to the unit matrix = = corresponding TranslateTransform, equivalent to the recovery operation angle + = change;//Set the angle of the next text} else {//input text for one time is special case, consider float x = (tem_line + circ) separately ULARITY_W/2)/2; Float y = (tem_line + CIRCULARITY_W/2)/2; G.translatetransform (x, y); G.rotatetransform (0); Brush MyBrush = brushes.red; float words_x =-circularity_w*3; float words_y =-(TEM_LINE/2-2 * circularity_w); g.DrawString (Inputwords.substring (i, 1), Var_font, MyBrush, words_x, words_y); G.resettransform (); }} #endregion} private void Simplebutton2_click (object sender, EventArgs e) {inputwords = Textbox_ text. Text; MessageBox.Show ("Saved successfully! "); } #endregion
Effect preview: