Asp.net implements the C # method for drawing a sequence chart,

Source: Internet
Author: User

Asp.net implements the C # method for drawing a sequence chart,

The example in this article describes how to use asp.net to implement a C # plot. Share it with you for your reference. The details are as follows:

The finished diagram is as follows:

Html page:

Note settings:

Copy codeThe Code is as follows: ContentType = "Image/Jpeg"

Copy codeThe Code is as follows: <% @ 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>

Background code:

Copy codeThe Code is 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 the image quality
Graphics. CompositingQuality = CompositingQuality. HighQuality;
Graphics. SmoothingMode = SmoothingMode. AntiAlias;
Graphics. InterpolationMode = InterpolationMode. HighQualityBicubic;

// The background color is white.
Brush white = new SolidBrush (Color. White );
Graphics. FillRectangle (white, new Rectangle (0, 0, imgWidth, imgWidth ));

Brush blue = new SolidBrush (Color. Blue); // defines the blue Brush.
Brush red = new SolidBrush (Color. Red); // defines the red Brush.

// Fill the entire circle in blue
Graphics. FillPie (blue, 0, 0, imgWidth, imgWidth, and 0,360 );

// Define the path on the right (in red)
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 in the right part
Graphics. FillPath (red, redPath );
// Fill the red eye
Graphics. FillPie (red, new Rectangle (headDiameter/2-eyeRadius, headDiameter-eyeRadius, eyeRadius * 2, eyeRadius * 2), 0,360 );
// Fill the blue eyes
Graphics. FillPie (blue, new Rectangle (headDiameter + headDiameter/2-eyeRadius, headDiameter-eyeRadius, eyeRadius * 2, eyeRadius * 2), 0,360 );

Graphics. Dispose ();

// Write the data to the Response output stream, with normal quality
// Image. Save (Response. OutputStream, ImageFormat. Jpeg );

// Modify the Image Storage Quality
ImageCodecInfo myImageCodecInfo = GetEncoder (ImageFormat. Jpeg );
MyEncoder = Encoder. Quality;
MyEncoderParameters = new EncoderParameters (1 );
// Image Quality Grade
MyEncoderParameter = new EncoderParameter (myEncoder, 100L );
MyEncoderParameters. Param [0] = myEncoderParameter;

// Output with 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 C # programming.

Related Article

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.