用C# GDI+画太极图

研究GDI+了,发现这个东东挺不错的,可以实现很多挺cool的效果,今天尝试画了一个太极图,希望看过的朋友的否极泰来 
(CSDN的这个博客太垃圾了,经常不能传图,本来想把图给大家看的,只好放到别的地方通过链接来访问了)

废话少说,看代码:
aspx部分:

<% @ Page Language = " C# "  AutoEventWireup = " true "  CodeFile = " Taiji.aspx.cs "  Inherits = " Taiji "  ContentType = " Image/Jpeg "   %>

<! 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 >
    
    
</ div >
    
</ form >
</ body >
</ html >

(注意:第一行的最末尾有:ContentType="Image/Jpeg"语句)

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.Drawing2D;
using  System.Drawing.Imaging;
/*
 * 
 * 作者:周公
 * 日期:2007-8-16
 * 说明:这是周公用纯GDI+画出的一个太极图。演示了GraphicsPath的用法。
 * 
*/

public   partial   class  Taiji : System.Web.UI.Page
{
    
protected   void  Page_Load( object  sender, EventArgs e)
    {
        Bitmap image 
=   new  Bitmap( 400 400 ); // 图象尺寸
        Graphics graphics  =  Graphics.FromImage(image);
        Brush blue 
=   new  SolidBrush(Color.Blue); // 定义蓝色笔刷
        Brush red  =   new  SolidBrush(Color.Red); // 定义红色笔刷
        GraphicsPath leftPath  =   new  GraphicsPath(); // 初始化路径
        GraphicsPath rightPath  =   new  GraphicsPath(); // 初始化路径
        
// 定义左边的路径(蓝色部分)
        leftPath.AddArc( 0 0 400 400 0 180 );
        leftPath.AddArc(
0 100 200 200 0 - 180 );
        leftPath.AddArc(
200 100 200 200 0 180 );

        
// 定义右边的路径(红色部分)
        rightPath.AddArc( 0 0 400 400 0 - 180 );
        rightPath.AddArc(
0 100 200 200 0 - 180 );
        rightPath.AddArc(
200 100 200 200 0 180 );
        
// 填充左边部分
        graphics.FillPath(blue, leftPath);
        graphics.FillPie(red, 
new  Rectangle( 90 190 20 20 ),  0 360 ); // 填充眼睛
        
// 填充右边部分
        graphics.FillPath(red, rightPath);
        graphics.FillPie(blue, 
new  Rectangle( 290 190 20 20 ),  0 360 ); // 填充眼睛
        graphics.Dispose();
        image.Save(Response.OutputStream, ImageFormat.Jpeg);
// 写入到Response输出流中去
    }
}

说明:这里又展示了一种在asp.net中输出图象的方式,在本人的另一篇文章《asp.net中验证码的实现》中是通过程序设置ContentType的,而这里则是直接在aspx页面中设置,然后将画好的图片写入到当前Response对象的输出流中。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

周公

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值