成品图:

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);
//填充蓝色眼睛
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 C#绘制太极图的更多相关文章

  1. canvas一周一练 -- canvas绘制太极图(6)

    运行效果: <!DOCTYPE html> <html> <head> </head> <body> <canvas id=" ...

  2. asp.net中绘制大数据量的可交互的图表

    在一个asp.net项目中要用到能绘制大数据量信息的图表,并且是可交互的(放大.缩小.导出.打印.实时数据),能够绘制多种图形. 为此进行了多方调查预研工作,预研过微软的MsChart图表组件.基于j ...

  3. asp.net GDI+ 绘制椭圆 ,弧线,扇形

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  4. SVG绘制太极图

    思路:先画一整个圆,填充颜色为黑色,再用一个边框和填充颜色均为白色的长方形覆盖右半边的半圆,再以同一个圆心,相同半径绘制一整个圆,该圆的边线颜色为黑色,没有填充颜色,最后常规操作再画四个小圆 源代码: ...

  5. html5 canvas 绘制太极图

    <div class="container"> <canvas id="myCanvas" width="400" hei ...

  6. asp.net GDI+绘制五边形

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  7. asp.net GDI+绘制多个矩形

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  8. asp.net GDI+绘制折线

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  9. asp.net GDI+绘制矩形渐变

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

随机推荐

  1. .NET 并行编程——任务并行

    本文内容 并行编程 任务并行 隐式创建和运行任务 显式创建和运行任务 任务 ID 任务创建选项 创建任务延续 创建分离的子任务 创建子任务 等待任务完成 组合任务 任务中的异常处理 取消任务 Task ...

  2. BaseDAO使用

    BaseDao接口的过人之处在于:一般是提供从数据库 增加.删除.修改记录.查询所有记录.查询符合某个条件记录.取得某条记录等方法的底层数据操作自定义类.由于我们可能操作多个数据库表,这样就需要为每个 ...

  3. Jquery实现日期转换为 Unix时间戳及时间戳转换日期

    (function ($) { $.extend({ myTime: { /** * 当前时间戳 * @return <int> unix时间戳(秒) */ CurTime: functi ...

  4. Oracle 12c RMAN备份文档

    创建备份目录,查看剩余空间 [cistest@cistest ~]$ df -h df: '/home/oratest/.gvfs': Permission denied Filesystem Siz ...

  5. [转]Java NIO 系列教程

    Java NIO提供了与标准IO不同的IO工作方式: Channels and Buffers(通道和缓冲区):标准的IO基于字节流和字符流进行操作的,而NIO是基于通道(Channel)和缓冲区(B ...

  6. springboot 项目中获取默认注入的序列化对象 ObjectMapper

    在 springboot 项目中使用 @SpringBootApplication 会自动标记 @EnableAutoConfiguration 在接口中经常需要使用时间类型,Date ,如果想要格式 ...

  7. Atitit 错误处理机制:(1)静默模式(2)警告模式 (3)异常模式

    Atitit 错误处理机制:(1)静默模式(2)警告模式 (3)异常模式       三.     PDO的错误处理机制: (1)静默模式 默认情况下与mysql处理方式一致,不现实错误信息(静默模式 ...

  8. System.SerializableAttribute

    System.SerializableAttribute 串行化是指存储和获取磁盘文件.内存或其他地方中的对象.在串行化时,所有的实例数据都保存到存储介质上,在取消串行化时,对象会被还原,且不能与其原 ...

  9. Android中获取应用程序(包)的信息-----PackageManager的使用

    本节内容是如何获取Android系统中应用程序的信息,主要包括packagename.label.icon.占用大小等.具体分为两个 部分,计划如下: 第一部分: 获取应用程序的packagename ...

  10. python虚拟环境virtualenv的安装与使用

    如果我们要同时开发多个应用程序,每个应用可能需要各自拥有一套“独立”的Python运行环境,我们可以使用virtualenv解决这个问题,它可以为一个应用创建一套“隔离”的Python运行环境. 一. ...