ASP.NET描绘3D扇形立体拼图

时间:2008/4/20 13:22:25      阅读:4397          
估计很多朋友都用过WebChart的一个控件,俺就发一个不使用任何控件的ASP.NET描绘3D扇形立体拼图的代码,希望对大家有帮助,图片的描绘坐标如下图:
实现绘图如下:
 代码:
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Drawing2D

Partial Class Default2
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'设置ContentType的输出类型为Jpeg
Response.ContentType = "image/jpeg"

Const width As Integer = 300 '定义输出宽度
Const height As Integer = 300 '定义输出高度

Dim objBitmap As New Bitmap(width, height)
Dim objGraphics As Graphics = Graphics.FromImage(objBitmap)

'输出图像背景色
objGraphics.FillRectangle(New SolidBrush(Color.White), 0, 0, width, height)

Draw3DPieChart(objGraphics)

'把文件保存为指定图片格式
objBitmap.Save(Response.OutputStream, ImageFormat.Jpeg)

'释放使用的所有资源
objGraphics.Dispose()
objBitmap.Dispose()
End Sub

'描绘3D拼图,而且每切片是45度角
Private Sub Draw3DPieChart(ByRef objGraphics As Graphics)
Dim iLoop As Integer, iLoop2 As Integer

'创建位置和大小的椭圆。
Dim x As Integer = 50
Dim y As Integer = 20
Dim width As Integer = 200
Dim height As Integer = 100

'开始创建,每切片是45度角。
Dim startAngle As Integer = 0
Dim sweepAngle As Integer = 45
Dim objBrush As New SolidBrush(Color.Aqua)

Dim rand As New Random()
objGraphics.SmoothingMode
= SmoothingMode.AntiAlias
For iLoop = 0 To 315 Step 45

'从180度开始加上iLoop的值除以360度取余数(正数)
startAngle = (iLoop + 180) Mod 360
objBrush.Color
= Color.FromArgb(rand.[Next](255), rand.[Next](255), rand.[Next](255))

'填充扇形区立体阴影从0到180度(如果小于135度或等于180度则填充阴影)
If (startAngle < 135) OrElse (startAngle = 180) Then
For iLoop2 = 0 To 9
objGraphics.FillPie(
New HatchBrush(HatchStyle.Percent50, objBrush.Color), x, y + iLoop2, width, height, startAngle, sweepAngle)
Next
End If

'填充其它扇形区
If startAngle = 135 Then
'突出描绘固定角度的3D拼图并突出显示
For iLoop2 = 0 To 9
objGraphics.FillPie(
New HatchBrush(HatchStyle.Percent50, objBrush.Color), x - 30, y + iLoop2 + 15, width, height, startAngle, sweepAngle)
Next
objGraphics.FillPie(objBrush, x
- 30, y + 15, width, height, startAngle, sweepAngle)
Else
'填充没有立体阴影有扇形区
objGraphics.FillPie(objBrush, x, y, width, height, startAngle, sweepAngle)
End If
Next
End Sub


End Class

再增加一个WinFrom的3D Pie Chart,如下图:
评论
  • Re:ASP.NET描绘3D扇形立体拼图  (2008/8/11 15:32:02) by jl 
    够牛X......效果也不错
  • Re:ASP.NET描绘3D扇形立体拼图  (2008/9/4 22:09:00) by isaac au yeung 
    v我想問咁點樣加多幾個 item aar ?
  • Re:ASP.NET描绘3D扇形立体拼图  (2008/9/23 16:38:00) by 俞俞 
    最好能做成控件
  • Re:ASP.NET描绘3D扇形立体拼图  (2009/3/24 1:51:04) by 王影 
    学习一下,谢谢啦!
  • Re:ASP.NET描绘3D扇形立体拼图  (2009/4/10 14:50:22) by weiyelee 
    太强大了
  • Re:ASP.NET描绘3D扇形立体拼图  (2009/4/25 18:37:52) by liufeng 
    学习一下,谢谢
  • Re:ASP.NET描绘3D扇形立体拼图  (2009/9/26 12:02:17) by suncathay 

    很好,不错,收藏了!!

  • Re:ASP.NET描绘3D扇形立体拼图  (2009/12/29 17:36:38) by 天漪 

    <p>我靠,真漂亮.强就一个字,赞一个先</p>

  • Re:ASP.NET描绘3D扇形立体拼图  (2010/3/21 9:13:59) by 婵″倷缍嶆稉瀣祰閻㈤潧濂?Url= 

    功能好强大!

标 题:
 
姓 名:
 
主 页:

验证码:

评论:
 

Because of the cache,you may see your comments several minutes later.