asp.net realization of C # Drawing Taiji Method _ Practical skills

Source: Internet
Author: User

This article illustrates the method of asp.net to realize C # drawing the Taiji diagram. Share to everyone for your reference. Specifically as follows:

The finished product diagram looks like this:

HTML page:

Note settings:

Copy Code code as follows:
Contenttype= "Image/jpeg"

Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "TaiJiTu.aspx.cs" inherits= "Taijitu" contenttype= "image/" Jpeg "%>
<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>

<body>
<form id= "Form1" runat= "Server" >
<div>
</div>
</form>
</body>

Background code:

Copy Code code as follows:
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; Image size
int Eyeradius = IMGWIDTH/20; Fish Eye radius
int headdiameter = IMGWIDTH/2; Fish Head Diameter

Bitmap image = New Bitmap (ImgWidth, imgwidth);
Image. Setresolution (300, 300);

Graphics Graphics = graphics.fromimage (image);

Set Image quality
graphics.compositingquality = compositingquality.highquality;
Graphics. SmoothingMode = Smoothingmode.antialias;
Graphics. Interpolationmode = Interpolationmode.highqualitybicubic;

Background padding for White
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);

Whole circle filled with blue
Graphics. FillPie (blue, 0, 0, imgwidth, imgwidth, 0, 360);

Defines the path to the right (red section)
GraphicsPath redpath = new GraphicsPath ();//initialization path
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);
Fill the right part
Graphics. FillPath (red, Redpath);
Fill red eyes
Graphics. FillPie (Red, New Rectangle (HEADDIAMETER/2-Eyeradius, Headdiameter-eyeradius, Eyeradius * 2, Eyeradius * 2), 0, 360);
Fill Blue eyes
Graphics. FillPie (Blue, new Rectangle (Headdiameter + HEADDIAMETER/2-Eyeradius, Headdiameter-eyeradius, Eyeradius * 2, Eyeradiu S * 2), 0, 360);

Graphics. Dispose ();

Write to the response output stream, general quality
Image. Save (Response.outputstream, imageformat.jpeg);

Modify picture Save Quality
ImageCodecInfo myimagecodecinfo = Getencoder (imageformat.jpeg);
Myencoder = encoder.quality;
Myencoderparameters = new EncoderParameters (1);
Picture quality level
Myencoderparameter = new Encoderparameter (Myencoder, 100L);
Myencoderparameters.param[0] = Myencoderparameter;

Output using the specified parameter
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;
}
}

I hope this article will help you with the C # program.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.