首页 > 网站 > 建站经验 > 正文

asp.n_et实现C#绘制太极图的方法

2019-11-02 15:12:47
字体:
来源:转载
供稿:网友

 这篇文章主要介绍了asp.net实现C#绘制太极图的方法,实例分析了asp.net绘制图形的技巧,具有一定参考借鉴价值,需要的朋友可以参考下

  

本文实例讲述了asp.net实现C#绘制太极图的方法。分享给大家供大家参考。具体如下:

成品图如下所示:

asp.net实现C#绘制太极图的方法  电脑高手

html页面:

注意设置:

 

代码如下:ContentType="Image/Jpeg"

 

 

代码如下:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TaiJiTu.aspx.cs" Inherits="TaiJiTu" ContentType="Image/Jpeg" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>

 

后台代码:

 

代码如下:using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

public partial class TaiJiTu : System.Web.UI.Page
{
private Encoder myEncoder;
private EncoderParameter myEncoderParameter;
private EncoderParameters myEncoderParameters;
protected void Page_Load(object sender, EventArgs e)
{
int imgWidth = 400; //图象尺寸
int eyeRadius = imgWidth / 20; //鱼眼半径
int headDiameter = imgWidth / 2; //鱼头直径

Bitmap image = new Bitmap(imgWidth, imgWidth);
image.SetResolution(300, 300);

Graphics graphics = Graphics.FromImage(image);

//设置图像质量
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

 

//底色填充为白色
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);

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表