asp.net C # drawing Taiji __.net

Source: Internet
Author: User

Finished Product chart:


HTML page:

Note Settings

Contenttype= "Image/jpeg"

<%@ Page language= "C #" autoeventwireup= "true" codefile= "TaiJiTu.aspx.cs" inherits= "Taijitu" contenttype= "image/" Jpeg "%>

<! DOCTYPE html>


Background code:

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;
        The background is filled with white Brush = new SolidBrush (color.white); Graphics. FillRectangle (White, new Rectangle (0, 0, imGwidth, ImgWidth)); Brush blue = new SolidBrush (color.blue);//define the color brush Brush red = new SolidBrush (color.red);//define Red brush//whole round fill blue Color 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); Fills the right part of the graphics.

        FillPath (red, Redpath); Fill red eye graphics. 
        FillPie (Red, New Rectangle (HEADDIAMETER/2-Eyeradius, Headdiameter-eyeradius, Eyeradius * 2, Eyeradius * 2), 0, 360); Filled with 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 Preservation 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; Outputs the image using the specified parameters.
    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; }
}


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.