网站首页 新闻首页 网页设计图形动画软件编程网站开发办公软件操作系统数据库网络技术认证考试范文资料黑客攻防 书籍教程 进入论坛

C#中使用GDI+让网站新闻标题个性化

http://www.diybl.com/ 2008-4-22  网络 点击:  [ 评论 ]
文章搜索:    【点击打包该文章】

有时,我们需要让新闻标题更加个性化,如下图:
新华网新闻头条图片

上面这幅图片是新华网上的今日头条的标题。
我们一般的做法可能是:使用Photoshop制作成图片,保存上传。这样需要浪费人力,比较麻烦。有没有更好的办法呢?

下面使用GDI+及C#代码,完成自动实现的过程。

老规矩,先看看运行效果:
在线生成新闻标题

下面是C#代码:
// Text2Image.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Text2Image.aspx.cs" Inherits="BrawDraw.Com.Utility.Utility_Text2Image" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>生成图片验证码</title>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>

// Text2Image.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.IO;

namespace BrawDraw.Com.Utility
{
    public partial class Utility_Text2Image : System.Web.UI.Page
    {
        int _width = 480;
        public int Width
        {
            get
            {
                return _width;
            }
            set
            {
                _width = value;
            }
        }

        int _height = 66;
        public int Height
        {
            get
            {
                return _height;
            }
            set
            {
                _height = value;
            }
        }

        string _text = string.Empty;
        public string Text
        {
            get
            {
                return _text;
            }
            set
            {
                _text = value;
            }
        }

        string _fontName = "宋体";
        public string FontName
        {
      

欢迎光临DIY部落,点击这里查看更多文章教程   【点击打包该文章】
如果图片或页面不能正常显示请点击这里 站内搜索:   
上一篇文章:C#的委托与事件
下一篇文章:e.hasMorePages有一个用法

文章评论

请您留言