All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
用ASP.NET2.0如何随机读取Access记录?_.net资料_编程技术
ADO.NET数据库实例教程_[Asp.Net教程]
利用PHP和CSS改变网页文字大小_php资料_编程技术
关于php正则表达式的两点备注_php资料_编程技术
GridView,批量删除,自定义分页,定位页码_[Asp.Net教程]
asp.net,控件开发(一)---显示控件内容_[Asp.Net教程]
如何用.NET,Array类的Sort方法分类数值_.net资料_编程技术
ASP.NET中的File类和Directory类的相关知识_.net资料_编程技术
PHP中多张图片上传并校验的实现_[PHP教程]
安全知识:如何隐藏,PHP文件后门的技巧_php资料_编程技术
Reading number is top 10 pictures
Sora aoi in China4
Summer is most suitable for young people to travel in China7
Fierce! China's special forces training the devil1
Average female college students3
2012 national geographic daily picture7
Is said to be a Chinese female artist fame explicit pictures before1
007 James. bond's new lover
The money of more than 100 countries and regions22
Look for from human art net, is good--3
Small QiShu -- ShuangShuangPan2
Download software ranking
Ashlynn Video4
Sora aoi, the nurse, uniform ,nursing assistant
终极变速大师Speeder3.26
金山office2007
The cock of the Grosvenor LTD handsome
Boxer's Top ten classic battle5
星际争霸1.08硬盘免安装版
软件工程思想
变速齿轮3.26
Sora aoi‘s film--Lust fan wall
归海一刀 published in(发表于) 2014/1/30 1:10:17 Edit(编辑)
如何用.NET技术在线生成网站LOGO_[Asp.Net教程]

如何用.NET技术在线生成网站LOGO_[Asp.Net教程]

如何用.NET技术在线生成网站LOGO_[Asp.Net教程]

也许大家一看标题就知道,又是老生常谈了,在线生成LOGO其实就是在线生成图片,原理听起来很简单:
1. new一个bitmap或类似之物;


2. 用一个graphic在上边画出你想要的东西;


3. 保存,显示出来,大功告成.


今天要说的是生成中的一些细节问题.没有真正做过,你可能永远也不知道有这样的问题.下边提到的问题和代码,希望对各位有所帮助.


本文的示例程序在http://www.ladysolution.cn/logo.aspx


一. 字体位置.


用不同的字体,如果通过计算字体高度来给字体定位是不精确的,不同的字体有不同的em baseline,而且descending 和 ascending 得出来的值几乎很难用来算精确高度,更麻烦的是如果字体是某人造的,那EM更靠不住,最大的问题是文字上方的空白目前我没有找到适合的公式来计算.我用的是比较笨的办法,计算精确的字体高度:



private static int[] GetRealFontHeight(Bitmap bmp)
{
int width, height;
int frequency = 2;// higher frequency gets lower performance.
int[] ret = new int[2];
Color c;
bool goOut = false;
for (height = 1; height < bmp.Height - 1; height += frequency)
{
for (width = 1; width < bmp.Width - 1; width += frequency)
{
c = bmp.GetPixel(width, height);
if (c.Name.Length>0 && c.Name != "0")//got it!
{
ret[0] = height;
goOut = true;
break;
}
else
{
goOut = false;
}
}
if (goOut)
break;
}


goOut = false;
for (height = bmp.Height - 1; height > 1; height -= frequency)
{
for (width = bmp.Width - 1; width > 1; width -= frequency)
{
c = bmp.GetPixel(width, height);
if (c.Name.Length > 0 && c.Name != "0")
{
ret[1] = height;
goOut = true;
break;
}
else
{
goOut = false;
}
}
if (goOut)
break;
}


return ret;
}


在画图之前,用这个方法确定精确的字体高度,这样的染色的时候才不至于走样.大家可以通过http://www.ladysolution.cn/logo.aspx 生成图片看一下效果.如果用GDI+自带的计算高度的方法,比如GetHeight()和Height属性,在blend的时候换个字体必定有误差.


二. 画倒影, RotateFlip依然是主力


倒影倒是很简单,把BLEND设好,定位好,画出来就行:



Create mirror#region Create mirror


…….


Graphics gBack_mirror = Graphics.FromImage(backImage_mirror);


pStart = new Point(1, -pre[0]);


pEnd = new Point(1, pre[1] - pre[0]);


LinearGradientBrush backColor_mirror = new LinearGradientBrush(pStart, pEnd, Color.White, endColor);


……


gBack_mirror.DrawString(logoText, logoFont, backColor_mirror, new PointF(.0f, -pre[0]));


……


gBack.DrawImage(backImage_mirror, new Point(0, pre[1]+3));


#endregion


三. 计算好你的下笔点,通过第一点中的方法,可以拿到某字体在某size时的实际高度有多少,这样我们在画笔或写字之前通过调用此方法就可以得出你的着笔点的坐标:



private static int[] prerendText(int LogoWidth, int LogoHeight, string logoText, Font logoFont)


{


Bitmap bp = new Bitmap(LogoWidth, LogoHeight);


Graphics g = Graphics.FromImage(bp);


g.DrawString(logoText, logoFont, SystemBrushes.Info, new PointF(.0f, .0f));


int[] ret = new int[2];


ret = GetRealFontHeight(bp);


g.Dispose();


bp.Dispose();


return ret;


}


此方法返回某字体在某size下的最上方坐标和最下方坐标,有了坐标就好办事了:




int[] pre = prerendText(LogoWidth, LogoHeight, logoText, logoFont);


……


Point pStart = new Point(1, pre[0]-2);


Point pEnd = new Point(1, pre[1]+2);


LinearGradientBrush backColor = new LinearGradientBrush(pStart, pEnd, startColor, endColor);


return filename;


使用这种方法,画出来的图会比只用GDI+画出来更漂亮些,颜色更准确些.


来源:http://www.cnblogs.com/dingsea







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.