SoFunction
Updated on 2025-03-07

C# custom signature stamp implementation method

This article describes the implementation method of C# custom signature chapter. Share it for your reference. The specific implementation method is as follows:

using System;
using ;
using ;
using ;
using ;
using ;
using .Drawing2D;
namespace WfpApp
{
 public class DrawCachet
 {
  /// <summary>
  /// Custom oval signature stamp  /// </summary>
  /// <param name="Width">Width, the signature stamp drawn is only half of this width</param>  /// <param name="Height">Height, the signature seal drawn is only half of this height</param>  /// <param name="test">Name on the signature seal</param>  /// <param name="IsRotate">Is the signature stamp rotated angle</param>  /// <param name="angle">Size of rotation angle</param>  /// &lt;returns&gt;&lt;/returns&gt;
  public static Bitmap GetDrawCircleCachet(int Width, int Height, string test, bool IsRotate, int angle)
  {
   //Record the thickness of the circle brush   int Circle_Brush = 2;
   //canvas   Bitmap bitmap = new Bitmap(Width, Height);
   //Define the style of the string   Font var_Font = new Font("Arial", 13, );
   //Define a rectangle and set the drawing area of ​​the circle   Rectangle rect = new Rectangle(10, 10, Width / 2, Height / 2);
   //Instantiate Graphic class   Graphics g = (bitmap);
   //Eliminate the jagging of drawing the figure and smooth    = .;
   //Empty the panelCachet canvas background with white   ();
   //Set the color of the brush   Pen mypen = new Pen(, Circle_Brush);
   //Draw the circle   (mypen, rect);
   //Set the font style of the text   Font star_Font = new Font("Arial", 12, );
   //Perform width and length measurement of string   SizeF var_Size = (test, star_Font);
   float CircleZjW =  + 2 * Circle_Brush;
   float CircleZJH =  + 2 * Circle_Brush;
   float x = (CircleZjW - var_Size.Width) / 2F + ;
   float y = (CircleZJH - var_Size.Height) / 2F + ;
   //Draw text at the specified location   (test, star_Font, , new PointF(x, y));
   if (IsRotate)
    bitmap = Rotate(bitmap, angle);
   return bitmap;
  }
  /// &lt;summary&gt;
  /// Custom rectangle signature stamp  /// &lt;/summary&gt;
  /// <param name="width">Width, the signature stamp drawn is only half of this width</param>  /// <param name="height">height, the signature seal drawn is only half of this height</param>  /// <param name="name">Name on the signature seal</param>  /// <param name="IsRotate">Is the signature stamp rotated angle</param>  /// <param name="angle">Size of rotation angle</param>  /// &lt;returns&gt;&lt;/returns&gt;
  public static Bitmap GetDrawRectangle(int width, int height, string name, bool IsRotate, int angle)
  {
   //Record the thickness of the circle brush   int Circle_Brush = 2;
   //canvas   Bitmap bitmap = new Bitmap(width, height);
   //Define the style of the string   Font var_Font = new Font("Arial", 13, );
   //Define a rectangle and set the drawing area of ​​the circle   Rectangle rect = new Rectangle(10, 10, width / 2, height / 2);
   //Instantiate Graphic class   Graphics g = (bitmap);
   //Eliminate the jagging of drawing the figure and smooth    = .;
   //Empty the panelCachet canvas background with white   ();
   //Set the color of the brush   Pen mypen = new Pen(, Circle_Brush);
   //Draw the circle   (mypen, rect);
   //Set the font style of the text   Font star_Font = new Font("Arial", 12, );
   //Perform width and length measurement of string   SizeF var_Size = (name, star_Font);
   float CircleZjW =  + 2 * Circle_Brush;
   float CircleZJH =  + 2 * Circle_Brush;
   float x = (CircleZjW - var_Size.Width) / 2F + ;
   float y = (CircleZJH - var_Size.Height) / 2F + ;
   //Draw text at the specified location   (name, star_Font, , new PointF(x, y));
   if (IsRotate)
    bitmap = Rotate(bitmap, angle);
   return bitmap;
  }
  /// &lt;summary&gt;
  /// Signature seal spin  /// &lt;/summary&gt;
  /// <param name="b">Bitmap stamp</param>  /// <param name="angle">Rotation</param>  /// &lt;returns&gt;&lt;/returns&gt;
  static Bitmap Rotate(Bitmap b, int angle)
  {
   angle = angle % 360;
   //Ray conversion   double radian = angle *  / 180.0;
   double cos = (radian);
   double sin = (radian);
   //The width and height of the original picture   int w = ;
   int h = ;
   int W = (int)(((w * cos - h * sin), (w * cos + h * sin)));
   int H = (int)(((w * sin - h * cos), (w * sin + h * cos)));
   //Target bitmap   Bitmap dsImage = new Bitmap(W, H);
    g = (dsImage);
    = .;
    = .;
   // Calculate the offset   Point Offset = new Point((W - w) / 2, (H - h) / 2);
   //Construct the image display area: make the center of the image consistent with the center point of the window   Rectangle rect = new Rectangle(, , w, h);
   Point center = new Point( +  / 2,  +  / 2);
   (, );
   (360 - angle);
   //Restore the image translation in horizontal and vertical directions   (-, -);
   (b, rect);
   //Return to all transformations of drawing   ();
   ();
   ();
   //("", );
   return dsImage;
  }
 }
}

I hope this article will be helpful to everyone's C# programming.