国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#自定義簽名章實現方法

2020-01-24 01:30:46
字體:
來源:轉載
供稿:網友

本文實例講述了C#自定義簽名章實現方法。分享給大家供大家參考。具體實現方法如下:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using System.Drawing.Imaging;using System.Drawing.Drawing2D;namespace WfpApp{ public class DrawCachet {  /// <summary>  /// 自定義橢圓形簽名章  /// </summary>  /// <param name="Width">寬度,畫出的簽名章只有這寬度的一半</param>  /// <param name="Height">高度,畫出的簽名章只有這高度的一半</param>  /// <param name="test">簽名章上名字</param>  /// <param name="IsRotate">簽名章是否旋轉角度</param>  /// <param name="angle">旋轉角度的大小</param>  /// <returns></returns>  public static Bitmap GetDrawCircleCachet(int Width, int Height, string test, bool IsRotate, int angle)  {   //記錄圓畫筆的粗細    int Circle_Brush = 2;   //畫布   Bitmap bitmap = new Bitmap(Width, Height);   //定義字符串的樣式    Font var_Font = new Font("Arial", 13, FontStyle.Bold);   //定義一個矩形 ,設置圓的繪制區    Rectangle rect = new Rectangle(10, 10, Width / 2, Height / 2);   //實例化Graphic類    Graphics g = System.Drawing.Graphics.FromImage(bitmap);   //消除繪制圖形的鋸齒,平滑   g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;   //以白色清空panelCachet畫布背景    g.Clear(Color.White);   //設置畫筆的顏色   Pen mypen = new Pen(Color.Red, Circle_Brush);   //繪制圓    g.DrawEllipse(mypen, rect);   //設置文字的字體樣式    Font star_Font = new Font("Arial", 12, FontStyle.Regular);   //對字符串進行寬度和長度測量    SizeF var_Size = g.MeasureString(test, star_Font);   float CircleZjW = rect.Width + 2 * Circle_Brush;   float CircleZJH = rect.Height + 2 * Circle_Brush;   float x = (CircleZjW - var_Size.Width) / 2F + rect.X;   float y = (CircleZJH - var_Size.Height) / 2F + rect.Y;   //在指定的位置繪制文字   g.DrawString(test, star_Font, mypen.Brush, new PointF(x, y));   if (IsRotate)    bitmap = Rotate(bitmap, angle);   return bitmap;  }  /// <summary>  /// 自定義矩形簽名章  /// </summary>  /// <param name="width">寬度,畫出的簽名章只有這寬度的一半</param>  /// <param name="height">高度,畫出的簽名章只有這高度的一半</param>  /// <param name="name">簽名章上名字</param>  /// <param name="IsRotate">簽名章是否旋轉角度</param>  /// <param name="angle">旋轉角度的大小</param>  /// <returns></returns>  public static Bitmap GetDrawRectangle(int width, int height, string name, bool IsRotate, int angle)  {   //記錄圓畫筆的粗細    int Circle_Brush = 2;   //畫布   Bitmap bitmap = new Bitmap(width, height);   //定義字符串的樣式    Font var_Font = new Font("Arial", 13, FontStyle.Bold);   //定義一個矩形 ,設置圓的繪制區    Rectangle rect = new Rectangle(10, 10, width / 2, height / 2);   //實例化Graphic類    Graphics g = System.Drawing.Graphics.FromImage(bitmap);   //消除繪制圖形的鋸齒,平滑   g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;   //以白色清空panelCachet畫布背景    g.Clear(Color.White);   //設置畫筆的顏色   Pen mypen = new Pen(Color.Red, Circle_Brush);   //繪制圓    g.DrawRectangle(mypen, rect);   //設置文字的字體樣式    Font star_Font = new Font("Arial", 12, FontStyle.Regular);   //對字符串進行寬度和長度測量    SizeF var_Size = g.MeasureString(name, star_Font);   float CircleZjW = rect.Width + 2 * Circle_Brush;   float CircleZJH = rect.Height + 2 * Circle_Brush;   float x = (CircleZjW - var_Size.Width) / 2F + rect.X;   float y = (CircleZJH - var_Size.Height) / 2F + rect.Y;   //在指定的位置繪制文字   g.DrawString(name, star_Font, mypen.Brush, new PointF(x, y));   if (IsRotate)    bitmap = Rotate(bitmap, angle);   return bitmap;  }  /// <summary>  /// 簽名章旋轉  /// </summary>  /// <param name="b">Bitmap圖章</param>  /// <param name="angle">旋轉度</param>  /// <returns></returns>  static Bitmap Rotate(Bitmap b, int angle)  {   angle = angle % 360;   //弧度轉換   double radian = angle * Math.PI / 180.0;   double cos = Math.Cos(radian);   double sin = Math.Sin(radian);   //原圖的寬和高   int w = b.Width;   int h = b.Height;   int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin)));   int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos)));   //目標位圖   Bitmap dsImage = new Bitmap(W, H);   System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);   g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;   g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;   //計算偏移量   Point Offset = new Point((W - w) / 2, (H - h) / 2);   //構造圖像顯示區域:讓圖像的中心與窗口的中心點一致   Rectangle rect = new Rectangle(Offset.X, Offset.Y, w, h);   Point center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);   g.TranslateTransform(center.X, center.Y);   g.RotateTransform(360 - angle);   //恢復圖像在水平和垂直方向的平移   g.TranslateTransform(-center.X, -center.Y);   g.DrawImage(b, rect);   //重至繪圖的所有變換   g.ResetTransform();   g.Save();   g.Dispose();   //dsImage.Save("yuancd.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);   return dsImage;  } }}

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 呼图壁县| 南部县| 新密市| 郴州市| 紫阳县| 宁河县| 西乌| 芜湖县| 绩溪县| 谢通门县| 永靖县| 积石山| 卢湾区| 仁寿县| 京山县| 修水县| 龙游县| 咸阳市| 招远市| 曲沃县| 彰化县| 海门市| 永顺县| 台南市| 灌云县| 嵊州市| 崇义县| 福安市| 大余县| 柘城县| 鹿泉市| 楚雄市| 玉溪市| 松阳县| 石城县| 买车| 松江区| 宜丰县| 阳信县| 二连浩特市| 吉安市|