• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

asp.net实现C#绘制太极图的方法

asp 搞代码 4年前 (2022-01-03) 15次浏览 已收录 0个评论

这篇文章主要介绍了asp.net实现C#绘制太极图的方法,实例分析了asp.net绘制图形的技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了asp.net实现C#绘制太极图的方法。分享给大家供大家参考。具体如下:

成品图如下所示:

html页面:

注意设置:

代码如下:
ContentType=”Image/Jpeg”

代码如下:
 
 
 
 
     
 
 
     
   

 
   

 
     
 

后台代码:

代码如下:
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 = In

来源gao!%daima.com搞$代*!码网

terpolationMode.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#绘制太极图的方法的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:asp.net实现C#绘制太极图的方法

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址