ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 个性印章及公章的画法及实现

个性印章及公章的画法及实现

原创 Linux操作系统 作者:大可山 时间:2009-01-06 10:37:37 0 删除 编辑

先看效果:
1.公章

公章效果演示

 2. 个人印章效果:

个性化私人印章效果演示


这里粘出关键代码:

  private void DrawSeal()
  {
   RetrieveAll();
   if(this.SealType == SealType.OfficeSeal)
   {
    DrawOfficeSeal();
   }
   else
   {
    DrawPersonalSeal();
   }

   panelDisplayResultBitmap.AutoScroll = true;
   panelDisplayResultBitmap.AutoScrollMinSize = new Size ((int)(m_Bitmap.Width * Zoom), (int)(m_Bitmap.Height * Zoom));
   panelDisplayResultBitmap.Invalidate();
  }

//得到相关参数:
  private void RetrieveAll()
  {
   int diameter = 220;
   try
   {
    diameter = int.Parse(this.txtBoxDiameter.Text);
   }
   catch(Exception exc)
   {
    MessageBox.Show("输入错误的公章直径!\n请确保是整数");
   }
   if(diameter>1000 || diameter < 100 )
   {
    MessageBox.Show("公章直径输入太大或太小了!");
    diameter = 220;
   }
   this.OfficeSealDiameter = diameter;

   string fontName = this.FontlistBox.Text;
   if(fontName == string.Empty)
   {
    fontName = "Times New Roman";
   }
   this.SelectedFontName = fontName;
   this.SelectedFontColorFromArgb = Color.FromArgb((int)this.FontColor_A.Value,(int)this.FontColor_R.Value,
    (int)this.FontColor_G.Value,(int)this.FontColor_B.Value);
  }

// 画公章:

  private void DrawOfficeSeal()
  {
   try
   {
    OfficeSealMaker sm = new OfficeSealMaker();
    osm.FamilyName = this.SelectedFontName;
    osm.IsBold = false;
    osm.IsEmbedNotice = false; //是否保留“勿作他用”的提示信息
    osm.Diameter = this.OfficeSealDiameter;
    osm.Style. = Style.PentagonalStars;//设置中间LOGO
    osm.OfficeName = this.txtBoxCompanyName.Text;
    osm.IsDrawInnerRect = false;
    osm.WordsColor = this.SelectedFontColorFromArgb;
    osm.BorderColor = this.SelectedFontColorFromArgb;
    //osm.TextVerHeight = (float)this.numericUpDownFontHeight.Value;
    osm.RatioX = (float)numericUpDownFontRatioX.Value / 100f;
    m_Bitmap = osm.Draw();
   }
   catch(Exception exc)
   {
    MessageBox.Show(exc.Message,"发生错误");
   }
  }

//画私章:

  private void DrawPersonalSeal()
  {
   //int stampWidth = int.Parse(this.txtBoxDiameter.Text);
   PersonalSeal personalSeal = new PersonalSeal();
   personalSeal.SealColor = this.SelectedFontColorFromArgb;
   bool isYinSeal = false;
  
   if(this.cmbBoxYinYang.SelectedItem != null && this.cmbBoxYinYang.SelectedItem.ToString() == "阴章")
   {
    isYinSeal = true;
   }
   personalSeal.IsYinSeal = isYinSeal;
   string sealWords = this.txtBoxPersonalSealWords.Text.Trim();
   if(sealWords.Length != 4)
   {
    sealWords = "美中印章";
   }
   personalSeal.SealWords = sealWords;
   personalSeal.FontFamilyName = this.SelectedFontName;
   personalSeal.IsDrawInnerBorder = false;
   personalSeal.BorderWidth = 10;
   personalSeal.Celling = 0;

   int personalSealWidth = 100;
   try
   {
    personalSealWidth = int.Parse(this.txtBoxWidth.Text);
   }
   catch(Exception exc)
   {
    MessageBox.Show("输入有误,请输入整数!");
   }

   int personalSealHeight = 100;
   try
   {
    personalSealHeight = int.Parse(this.txtBoxHeight.Text);
   }
   catch(Exception exc)
   {
    MessageBox.Show("输入有误,请输入整数!");
   }

   personalSeal.Width = personalSealWidth;
   personalSeal.Height = personalSealHeight;

   m_Bitmap = (Bitmap)personalSeal.Draw();
  }

//私人印章的画法:
public System.Drawing.Image Draw()
  {
   Bitmap m_Bitmap;
   Color sealColor = Color.Red;
   int sealWidth = this.Width;
   int sealHeight = this.Height;
   int celling = this.Celling;
   int penWidth = this.BorderWidth;
   int cornerRadius = this.CornerRadius;
   Rectangle rect = new Rectangle(0, 0, sealWidth, sealHeight);
   Rectangle rectInner = new Rectangle(penWidth + celling, penWidth + celling, sealWidth - (penWidth + celling) * 2, sealHeight - (penWidth + celling) * 2);
   m_Bitmap = new Bitmap(sealWidth, sealHeight);
   Graphics g = Graphics.FromImage(m_Bitmap);
   g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
   g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
   g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
   //g.Clear(Color.White);

   Pen pen = new Pen(sealColor, penWidth);
   pen.Alignment = PenAlignment.Inset;

   //画个人印章的外部圆角矩形
   RoundRectangeHelper.DrawRoundRectangle(g, pen, rect, cornerRadius);

   pen = new Pen(this.SealColor, this.InnerBorderWidth);
   if(this.IsDrawInnerBorder)
   {
    g.DrawRectangle(pen, rectInner);
   }

   //画字
   Font font;
   try
   {
    font = new Font(this.FontFamilyName, 20f);
   }
   catch(Exception exc)
   {
    font = new Font("Times New Roman",20f);
   }
   Color fillColor;
   if(this.IsYinSeal)
   {
    fillColor = Color.White;
    g.FillRectangle(new SolidBrush(this.SealColor), rectInner);
   }
   else
   {
    fillColor = this.SealColor;
   }

   string word = this.SealWords;
   int[] rderSrc = {1,2,3,4};
   int[] rderDest = {2,4,1,3};
   char[] words = word.ToCharArray();
   char[] wordsTmp = new char[words.Length];
   words.CopyTo(wordsTmp, 0);
   for(int i = 0; i < orderSrc.Length; i++)
   {
    words[orderDest[i] - 1] = wordsTmp[orderSrc[i] - 1];
   }

   Rectangle rect1 = new Rectangle(rectInner.X, rectInner.Y, rectInner.Width/2, rectInner.Height/2);
   Rectangle rect2 = new Rectangle(rectInner.X + rectInner.Width/2, rectInner.Y, rectInner.Width/2, rectInner.Height/2);
   Rectangle rect3 = new Rectangle(rectInner.X, rectInner.Y + rectInner.Height/2, rectInner.Width/2, rectInner.Height/2);
   Rectangle rect4 = new Rectangle(rectInner.X + rectInner.Width/2, rectInner.Y + rectInner.Height/2, rectInner.Width/2, rectInner.Height/2);
   Rectangle[] rects = new Rectangle[]
    {
     rect1, rect2, rect3, rect4
    };

   for(int i = 0; i < 4; i++)
   {
    DrawWordIntoRectangle(g, words[i].ToString(), font, fillColor, rects[i]);
   }

   pen.Dispose();
   g.Dispose();

   return m_Bitmap;
  }


 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/14601556/viewspace-528572/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 图片的错觉效果
下一篇: 好书推荐
请登录后发表评论 登录
全部评论
IT人士,爱好编程的码农。

注册时间:2008-06-19

  • 博文量
    118
  • 访问量
    691016