您好,登录后才能下订单哦!
利用asp.net怎么绘制一个太极图?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
代码如下:
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);
//填充蓝色眼睛
graphics.FillPie(blue, new Rectangle(headDiameter + headDiameter / 2 - eyeRadius, headDiameter - eyeRadius, eyeRadius * 2, eyeRadius * 2), 0, 360);
graphics.Dispose();
//写入到Response输出流中去,普通质量
//image.Save(Response.OutputStream, ImageFormat.Jpeg);
//修改图片保存质量
ImageCodecInfo myImageCodecInfo = GetEncoder(ImageFormat.Jpeg);
myEncoder = Encoder.Quality;
myEncoderParameters = new EncoderParameters(1);
//图片质量等级
myEncoderParameter = new EncoderParameter(myEncoder, 100L);
myEncoderParameters.Param[0] = myEncoderParameter;
//使用指定参数输出
image.Save(Response.OutputStream, myImageCodecInfo, myEncoderParameters);
}
private static ImageCodecInfo GetEncoder(ImageFormat format)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.FormatID == format.Guid)
{
return codec;
}
}
return null;
}
}
看完上述内容,你们掌握利用asp.net怎么绘制一个太极图的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。