這篇文章主要介紹了asp.net實現C#繪制太極圖的方法,實例分析了asp.net繪制圖形的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了asp.net實現C#繪制太極圖的方法。分享給大家供大家參考。具體如下:
成品圖如下所示:

html頁面:
注意設置:
代碼如下:ContentType="Image/Jpeg"
代碼如下:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TaiJiTu.aspx.cs" Inherits="TaiJiTu" ContentType="Image/Jpeg" %>
后臺代碼:
代碼如下:using System;
//底色填充為白色
Brush white = new SolidBrush(Color.White);
graphics.FillRectangle(white, new Rectangle(0, 0, imgWidth, imgWidth));
Brush blue = new SolidBrush(Color.Blue);//定義藍色筆刷
Brush red = new SolidBrush(Color.Red);//定義紅色筆刷
//整個圓形填充藍色
graphics.FillPie(blue, 0, 0, imgWidth, imgWidth, 0, 360);
//定義右邊的路徑(紅色部分)
GraphicsPath redPath = new GraphicsPath();//初始化路徑
redPath.AddArc(0, 0, imgWidth, imgWidth, 0, -180);
redPath.AddArc(0, headDiameter / 2, headDiameter, headDiameter, 0, -180);
redPath.AddArc(headDiameter, headDiameter / 2, headDiameter, headDiameter, 0, 180);
//填充右邊部分
graphics.FillPath(red, redPath);
//填充紅色眼睛
graphics.FillPie(red, new Rectangle(headDiameter / 2 - eyeRadius, headDiameter - eyeRadius, eyeRadius * 2, eyeRadius * 2), 0, 360);
新聞熱點
疑難解答