程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#獲得過程或線程相干信息的辦法

C#獲得過程或線程相干信息的辦法

編輯:C#入門知識

C#獲得過程或線程相干信息的辦法。本站提示廣大學習愛好者:(C#獲得過程或線程相干信息的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#獲得過程或線程相干信息的辦法正文


本文實例講述了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#法式設計有所贊助。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved