ASP.NET Image Generation介绍


随着微软不断扩大开放源代码规模,Codeplex上最热门的项目就是ASP.NET。

  在ASP.NET WebForms下有个ASP.NET Image Generation子项目,为ASP.NET项目里处理图片带来了便利。

  项目简介:ASP.NET Image Generation is a speedy way of generating, transforming, caching images in ASP.net

  下载:http://aspnet.codeplex.com/Wiki/View.aspx?title=Image%20Generation&referringTitle=Home

  .Net Framework:3.5

  代码示例:

  Default.aspx

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="Microsoft.Web.GeneratedImage" Namespace="Microsoft.Web" TagPrefix="cc1" %>

<!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">
    <div>              
        <cc1:GeneratedImage ID="GeneratedImage1"
            runat="server" ImageHandlerUrl="~/TextImageHandler.ashx" >           
            <Parameters>
                <cc1:ImageParameter Name="Hello" Value="text in an image" />
            </Parameters>        
        </cc1:GeneratedImage>
    </div>
    </form>
</body>
</html>

  TextImageHandler.ashx

<%@ WebHandler Language="C#" Class="TextImageHandler" %>

using System;
using System.Collections.Specialized;
using System.Drawing;
using System.Web;
using Microsoft.Web;

public class TextImageHandler : ImageHandler {
   
    public TextImageHandler() {
        this.ContentType = System.Drawing.Imaging.ImageFormat.Png;
    }
   
    public override ImageInfo GenerateImage(NameValueCollection parameters) {
        // Add image generation logic here and return an instance of ImageInfo
        Bitmap bit = new Bitmap(300, 60);
        Graphics gra = Graphics.FromImage(bit);
        gra.Clear(Color.AliceBlue);
        gra.DrawString(parameters["Hello"], new Font(FontFamily.GenericSansSerif, 16), Brushes.Black, 0, 0);

        return new ImageInfo(bit);
    }
}

  运行效果



相关阅读:
PHP has encountered an Access Violation
HTML教程:HTML的10个表格相关标记
C#.Net 学习笔记(一)
Linux系统Fcitx中文输入法开机启动方法
用一个命令在xp下删除非空目录
asp.net XMLHttpRequest实现用户注册前的验证
linux/unix vi 编辑器用法详解
CSS Sprite优化 减少HTTP链接数
HTML5教程:article标签
PHP5安装配置和Zend Optimizer安装教程
CSS初学者常犯错误汇总
Joomla教程:mod-rewrite是否真的被开启
加快Vista文件复制速度的方法
fso的一些特殊功能
快速导航

Copyright © 2016 phpStudy |