C#个性印章及公章的画法及实现
先看效果:
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 osm = 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[] orderSrc = {1,2,3,4};
int[] orderDest = {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;
}
C#个性印章及公章的画法及实现相关推荐
- 个性印章及公章的画法及实现
声明:本程序系本人原创,引用时请保留以下信息: ---------------------------------------------------------------------------- ...
- 创建自己的网上个性印章
今天在泡泡糖的家里发现一个日志,感觉不错,推荐给大家: http://caishu.sina.com.cn/index.htm 利用这个网站可以很方便的生成自己的网上个性印章.赠言及书法真迹等. 生成 ...
- MakePic.com 图片制造 打造个性签名 拒绝垃圾邮件 生成个性印章
MakePic.com 图片制造 打造个性签名 拒绝垃圾邮件 生成个性印章 MakePic.com 图片制造 打造个性签名 拒绝垃圾邮件 生成个性印章 欢迎使用MakePic.com posted o ...
- 如何制作印章_如何用Photoshop制作个性印章/文字图片
带印章和文字的图片,不仅可以作为个人的标签,更能直接表达照片的意境,让片子与众不同. 那么,怎样才能给照片加印章和文字呢?或许方法有很多,甚至有多款App也可以直接做效果.但想要做出精细的效果,Pho ...
- 个性印章在线生成下载网站
个 性印盖在线生成下载网站 :[url]http://yz.yibudong.com/[/url] 印 章篆体,方印 印 章篆体,方印 印 章仿黑,圆印 印 章仿黑,圆印 印 章古隶,方印 印 章古隶 ...
- 在WPF中制作正圆形公章
之前,我利用C#与GDI+程序制作过正圆形公章(利用C#制作公章 ,C#制作公章[续])并将它集成到一个小软件中(个性印章及公章的画法及实现),今天我们来探讨一下WPF中如何制作正圆形公章. 先看大致 ...
- 手机界面视觉设计清单_如何改善您的产品用户界面设计师清单
手机界面视觉设计清单 重点 (Top highlight) This story is less about design trends and fashion, and more about fou ...
- 刻章不要钱 5个在线印章制作工具
俺的博客里的图片,还有网生代上俺写的文章很多都是用印章当作图片水印的.(奇怪的是,怎么没人眼馋?)有了现代科技,刻章其实很简单了,本文就介绍几个在线印章制作工具. 一.MakePic印章生成器 允许输 ...
- 不要钱 5个在线印章制作工具
俺的博客里的图片,还有网生代上俺写的文章很多都是用印章当作图片水印的.(奇怪的是,怎么没人眼馋?)有了现代科技,其实很简单了,本文就介绍几个在线印章制作工具. 一.MakePic印章生成器 允许输入2 ...
最新文章
- 阅读记录:Learning multiple layers of representation(杂乱笔记)
- 这是一个什么用也没有的模板
- 移植Python2到TQ2440
- 五分钟了解一致性hash算法!
- foreach jdk8 递归_[Java 8] (8) Lambda表达式对递归的优化(上) - 使用尾递归 .
- 部署mysql MHA集群
- html盒子中盒子排列,css3中弹性盒排布使用方法
- python中对象的特性_Python深入学习之对象的属性
- 栈的应用实例——平衡符号
- Python基础_第2章_Python运算符与if结构
- Python学习:简单的python “hello,world”程序
- 「镁客早报」苹果将在德国停售iPhone 7&8;“刘强东事件”正式结案...
- 程序员的算法趣题Q50: 完美洗牌
- 感激爸妈----您们辛苦了
- maven打包时依赖的项目包是时间戳而不是SNAPSHOT?
- java common log使用,log4j和commons.logging日志记录的使用方法
- HEVC 高级运动向量预测技术(AMVP)
- 201871010123-吴丽丽《面向对象程序设计(java)》第二周学习总结
- mysql 查看备份工具_MariaDB/MySQL备份和恢复(一):mysqldump工具用法详述【转】
- L1-概率论中的10个基本概念:古典概率、联合概率、条件概率、生日问题等
热门文章
- 使用eolinker接口返回结果入库
- OpenCL 通用编程与优化(3)
- 【python爬虫专项(24)】协调Selenium与requests+bs的方法
- C++编程的“读”与“写”操作
- java中的比较详解
- 在线刷网站流量(倍儿厉害)
- c语言中interrupt用法,C语言中的interrupt是怎么回事
- 东方博宜oj部分答案
- java marshal 序列化_求教Marshal类实现序列化出现的问题
- 实测SpringCloud Gateway网关性能(Wrk和Jmeter)