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);
//填充蓝色眼睛
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#绘制太极图的更多相关文章
- canvas一周一练 -- canvas绘制太极图(6)
运行效果: <!DOCTYPE html> <html> <head> </head> <body> <canvas id=" ...
- asp.net中绘制大数据量的可交互的图表
在一个asp.net项目中要用到能绘制大数据量信息的图表,并且是可交互的(放大.缩小.导出.打印.实时数据),能够绘制多种图形. 为此进行了多方调查预研工作,预研过微软的MsChart图表组件.基于j ...
- asp.net GDI+ 绘制椭圆 ,弧线,扇形
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- SVG绘制太极图
思路:先画一整个圆,填充颜色为黑色,再用一个边框和填充颜色均为白色的长方形覆盖右半边的半圆,再以同一个圆心,相同半径绘制一整个圆,该圆的边线颜色为黑色,没有填充颜色,最后常规操作再画四个小圆 源代码: ...
- html5 canvas 绘制太极图
<div class="container"> <canvas id="myCanvas" width="400" hei ...
- asp.net GDI+绘制五边形
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- asp.net GDI+绘制多个矩形
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- asp.net GDI+绘制折线
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- asp.net GDI+绘制矩形渐变
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
随机推荐
- Spark LDA实战
选取了10个文档,其中4个来自于一篇论文,3篇来自于一篇新闻,3篇来自于另一篇新闻. 首先在pom文件中加入mysql-connector-java: <dependency> <g ...
- CentOS7下 让Docker pull命令使用squid做http代理拉取目标镜像仓库的镜像
场景,如下图所示: 服务器B具有两个网卡,分别和服务器A和服务器C互通,这里想要在服务器C上借助服务器B作为桥梁,拉取镜像仓库服务器A上的镜像. 思路也很简单,在服务器上搭建HTTP代理服务,服务器C ...
- top命令详析及排查问题使用演示
1. top基本使用 top命令运行图 第一行:基本信息 第二行:任务信息 第三行:CPU使用情况 第四行:物理内存使用情况 buff/cache: buffers 和 cache 都是内存中存放的数 ...
- 【C#】C#对Excel表的操作
目录结构: contents structure [+] Microsoft.Office.Interop.Excel.Application Aspose.cell插件 1.Microsoft.Of ...
- 【Android】Android传感器
1.加速度传感器2.磁场传感器3.方向传感器4.陀螺仪传感器5.重力传感器6.线性加速度传感器7.温度传感器8.光线传感器9.距离传感器10.压力传感器11.计步传感器 首先先查看测试的安卓机拥有的传 ...
- Mac Apache WebServer 服务器配置
前言 Apache 是目前使用最广的 Web 服务器,可以支持各种脚本的执行. Mac 系统自带,无需单独安装,只需要修改几个配置就可以,简单,快捷. 有些特殊的服务器功能,Apache 都能很好的支 ...
- mysql 存储引擎对索引的支持
一.首先给出mysql官方文档给出的不同存储引擎对索引的支持 从上面的图中可以得知,mysql 是支持hash索引的,但支持和不支持又和具体的存储引擎有关系.从图中看到InnoDB是支持Btree索引 ...
- tensorflow 笔记11:tf.nn.dropout() 的使用
tf.nn.dropout:函数官网说明: tf.nn.dropout( x, keep_prob, noise_shape=None, seed=None, name=None ) Defined ...
- Asp.Net T4模板生成三层架构
1.T4 Editor安装 T4:根据模板生成文件,例如model等 vs中默认t4模板编码是没有提示和高亮的,需使用以下插件,免费的 https://t4-editor.tangible-engin ...
- JVM 内部原理(七)— Java 字节码基础之二
JVM 内部原理(七)- Java 字节码基础之二 介绍 版本:Java SE 7 为什么需要了解 Java 字节码? 无论你是一名 Java 开发者.架构师.CxO 还是智能手机的普通用户,Java ...