asp.net實(shí)現(xiàn)C#繪制太極圖的方法
本文實(shí)例講述了asp.net實(shí)現(xiàn)C#繪制太極圖的方法。分享給大家供大家參考。具體如下:
成品圖如下所示:
html頁(yè)面:
注意設(shè)置:
<!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>
后臺(tái)代碼:
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; //魚(yú)眼半徑
int headDiameter = imgWidth / 2; //魚(yú)頭直徑
Bitmap image = new Bitmap(imgWidth, imgWidth);
image.SetResolution(300, 300);
Graphics graphics = Graphics.FromImage(image);
//設(shè)置圖像質(zhì)量
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);//定義藍(lán)色筆刷
Brush red = new SolidBrush(Color.Red);//定義紅色筆刷
//整個(gè)圓形填充藍(lán)色
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);
//填充藍(lán)色眼睛
graphics.FillPie(blue, new Rectangle(headDiameter + headDiameter / 2 - eyeRadius, headDiameter - eyeRadius, eyeRadius * 2, eyeRadius * 2), 0, 360);
graphics.Dispose();
//寫入到Response輸出流中去,普通質(zhì)量
//image.Save(Response.OutputStream, ImageFormat.Jpeg);
//修改圖片保存質(zhì)量
ImageCodecInfo myImageCodecInfo = GetEncoder(ImageFormat.Jpeg);
myEncoder = Encoder.Quality;
myEncoderParameters = new EncoderParameters(1);
//圖片質(zhì)量等級(jí)
myEncoderParameter = new EncoderParameter(myEncoder, 100L);
myEncoderParameters.Param[0] = myEncoderParameter;
//使用指定參數(shù)輸出
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;
}
}
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
- Android 畫一個(gè)太極圖實(shí)例代碼
- JS實(shí)現(xiàn)太極旋轉(zhuǎn)思路分析
- C++俄羅斯方塊游戲 無(wú)需圖形庫(kù)的俄羅斯方塊
- c語(yǔ)言10個(gè)經(jīng)典小程序
- C語(yǔ)言字符串操作總結(jié)大全(超詳細(xì))
- C語(yǔ)言程序設(shè)計(jì)50例(經(jīng)典收藏)
- C語(yǔ)言文件操作函數(shù)大全(超詳細(xì))
- C語(yǔ)言/C++中如何產(chǎn)生隨機(jī)數(shù)
- c語(yǔ)言字符數(shù)組與字符串的使用詳解
- 利用C語(yǔ)言的Cairo圖形庫(kù)繪制太極圖實(shí)例教程
相關(guān)文章
asp.net LC.exe已退出代碼為 -1的原因分析及解決方法
錯(cuò)誤“LC.exe”已退出,代碼為 -1。是VS2005,并且在項(xiàng)目中引用了第三方組件。2013-06-06ASP.NET實(shí)現(xiàn)QQ、微信、新浪微博OAuth2.0授權(quán)登錄
本文主要介紹了QQ、微信、新浪微博OAuth2.0授權(quán)登錄的示例,主要就是GET、POST遠(yuǎn)程接口,返回相應(yīng)的數(shù)據(jù),這里列出相關(guān)的代碼,供大家參考。2016-03-03網(wǎng)頁(yè)(aspx)與用戶控件(ascx)交互邏輯處理實(shí)現(xiàn)
為了以后好維護(hù),把幾個(gè)頁(yè)面(ASPX)相同的部分抽取放在一個(gè)用戶控件(ASCX)上,現(xiàn)在把邏輯分享下,感興趣的各位可以參考下哈2013-03-03C#讀取中文字符及清空緩沖區(qū)的實(shí)現(xiàn)代碼
有一個(gè)txt的中英文語(yǔ)料庫(kù)文件,內(nèi)容是英文一句中文一句相間的,共3000行,需要把英文句和中文句分開(kāi),放在單獨(dú)的txt文件中。2010-12-12MultiLine 換行后實(shí)現(xiàn)讀取不換行的具體思路
輸入內(nèi)容中有換行,保存到數(shù)據(jù)庫(kù),直接查看感覺(jué)沒(méi)有換行,但查詢結(jié)果“以文本格式顯示結(jié)果”你就會(huì)發(fā)現(xiàn) 其實(shí)是有換行的,下面與大家分享下具體的解決方法2013-06-06使用DataTable更新數(shù)據(jù)庫(kù)(增,刪,改)
使用DataTable更新數(shù)據(jù)庫(kù)(增,刪,改),需要的朋友可以參考一下2013-03-03.Net語(yǔ)言Smobiler開(kāi)發(fā)之如何在手機(jī)上實(shí)現(xiàn)表單設(shè)計(jì)
這篇文章主要為大家詳細(xì)介紹了.Net語(yǔ)言APP開(kāi)發(fā)平臺(tái),如何在手機(jī)上實(shí)現(xiàn)表單設(shè)計(jì)(Smobiler),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09