欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實(shí)現(xiàn)網(wǎng)頁(yè)畫圖功能

 更新時(shí)間:2020年03月24日 10:42:24   作者:epleone  
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)網(wǎng)頁(yè)畫圖功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C#實(shí)現(xiàn)網(wǎng)頁(yè)畫圖的具體代碼,供大家參考,具體內(nèi)容如下

代碼貼著保存下

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
 
public partial class _Default : System.Web.UI.Page
{
  int h = 1000;
  int w = 1000;
  protected void Page_Load(object sender, EventArgs e)
  {
    Bitmap img = new Bitmap(h, w);//創(chuàng)建Bitmap對(duì)象
    MemoryStream stream = draw();
 
    img.Save(stream, ImageFormat.Jpeg);     //保存繪制的圖片
    Response.Clear();
    Response.ContentType = "image/jpeg";
    Response.BinaryWrite(stream.ToArray());
  }
 
  public MemoryStream draw()
  {
    string[] Words = {"壹","貳","叁","肆","伍","陸"};
    Bitmap img = new Bitmap(h, w);//創(chuàng)建Bitmap對(duì)象
    Graphics g = Graphics.FromImage(img);//創(chuàng)建Graphics對(duì)象
    g.DrawRectangle(new Pen(Color.White, img.Height), 2, 2, img.Width - 2, img.Height - 2); //矩形 底色
 
 
    ArrayList coordinate = getXY(Words.Length,img.Height,img.Width);
    ArrayList Radius = new ArrayList();
 
    var R = new Random();
    Color Mycolor = Color.FromArgb(R.Next(100, 150), R.Next(255), R.Next(255), R.Next(255));
 
    Font font = new Font("Arial", 20);// 字體
    LinearGradientBrush font_brush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.Black, Color.Black, 1.2F, true);
 
    int j = 0;
    //畫圓 寫字
    foreach (Point p in coordinate)
    {
      int r = R.Next(20, 40);
      Radius.Add(r);
      SolidBrush bush = new SolidBrush(Mycolor);
      g.FillEllipse(bush, p.X - r, p.Y - r, 2*r, 2*r);//畫填充橢圓的方法,x坐標(biāo)、y坐標(biāo)、寬、高:
 
      g.DrawString(Words[j++], font, font_brush, p); // 標(biāo)記
    }
 
    //連線
    var penColor = Color.FromArgb(140, R.Next(255), R.Next(255), R.Next(255));
    for (int i = 1; i < coordinate.Count; i++) 
    {
      Pen pen = new Pen(penColor, 2);
      g.DrawLine(pen, (Point)coordinate[0], (Point)coordinate[i]);
    }
    
    MemoryStream stream = new MemoryStream();  //保存繪制的圖片
    img.Save(stream, ImageFormat.Jpeg);     //保存繪制的圖片
    return stream;
  }
 
  private ArrayList getXY(int len, int h, int w) 
  {
    ArrayList al = new ArrayList();
    double d = 50.0;
    var R = new Random();
    int h1 = (int)(0.1 * h);
    int h2 = (int)(0.9 * h);
    int w1 = (int)(0.1 * w);
    int w2 = (int)(0.9 * w);
 
    while (al.Count < len) 
    {
      Point p = new Point(R.Next(h1,h2), R.Next(w1,w2));
      bool Add = true;
      foreach (Point q in al) 
      {
        if (Dist(p, q) < d)
        {
          Add = false;
          break;
        }
      }
      if (Add)
        al.Add(p);
 
    }
 
    return al;
  }
 
  private double Dist(Point p1,Point p2) 
  {
    return Math.Sqrt(Math.Abs(p1.X - p2.X) * Math.Abs(p1.X - p2.X) + Math.Abs(p1.Y - p2.Y) * Math.Abs(p1.Y - p2.Y));
  }
}

效果如下

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • c#固定長(zhǎng)度的隨機(jī)字符串例子

    c#固定長(zhǎng)度的隨機(jī)字符串例子

    c#固定長(zhǎng)度的隨機(jī)字符串例子,需要的朋友可以參考一下
    2013-04-04
  • C#基于HttpWebRequest實(shí)現(xiàn)發(fā)送HTTP請(qǐng)求的方法分析

    C#基于HttpWebRequest實(shí)現(xiàn)發(fā)送HTTP請(qǐng)求的方法分析

    這篇文章主要介紹了C#基于HttpWebRequest實(shí)現(xiàn)發(fā)送HTTP請(qǐng)求的方法,結(jié)合實(shí)例形式分析了C#使用HttpWebRequest類與System.IO類實(shí)現(xiàn)發(fā)送HTTP請(qǐng)求相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下
    2019-02-02
  • C# 當(dāng)前系統(tǒng)時(shí)間獲取及時(shí)間格式詳解

    C# 當(dāng)前系統(tǒng)時(shí)間獲取及時(shí)間格式詳解

    這篇文章主要介紹了C# 當(dāng)前系統(tǒng)時(shí)間獲取及時(shí)間格式詳解的相關(guān)資料,這里提供代碼實(shí)例,幫助大家學(xué)習(xí)參考,需要的朋友可以參考下
    2016-12-12
  • 深入了解c# 設(shè)計(jì)模式之簡(jiǎn)單工廠模式

    深入了解c# 設(shè)計(jì)模式之簡(jiǎn)單工廠模式

    這篇文章主要介紹了c# 設(shè)計(jì)模式之簡(jiǎn)單工廠模式的的相關(guān)資料,文中代碼非常詳細(xì),幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-06-06
  • winform c#中子窗體關(guān)閉刷新父窗體的實(shí)例

    winform c#中子窗體關(guān)閉刷新父窗體的實(shí)例

    下面小編就為大家?guī)?lái)一篇winform c#中子窗體關(guān)閉刷新父窗體的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-02-02
  • C#實(shí)現(xiàn)密碼驗(yàn)證與輸錯(cuò)密碼賬戶鎖定

    C#實(shí)現(xiàn)密碼驗(yàn)證與輸錯(cuò)密碼賬戶鎖定

    這篇文章介紹了C#實(shí)現(xiàn)密碼驗(yàn)證與輸錯(cuò)密碼賬戶鎖定的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-04-04
  • C#中TCP粘包問(wèn)題的解決方法

    C#中TCP粘包問(wèn)題的解決方法

    這篇文章主要為大家詳細(xì)介紹了C#中TCP粘包問(wèn)題的解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • C#遍歷DataSet控件實(shí)例總結(jié)

    C#遍歷DataSet控件實(shí)例總結(jié)

    這篇文章主要介紹了C#遍歷DataSet控件的用法,以實(shí)例形式總結(jié)歸納了常見的遍歷方法,具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2014-10-10
  • C#如何讀取Txt大數(shù)據(jù)并更新到數(shù)據(jù)庫(kù)詳解

    C#如何讀取Txt大數(shù)據(jù)并更新到數(shù)據(jù)庫(kù)詳解

    這篇文章主要給大家介紹了關(guān)于C#如何讀取Txt大數(shù)據(jù)并更新到數(shù)據(jù)庫(kù)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用C#具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • C#多線程系列之線程完成數(shù)

    C#多線程系列之線程完成數(shù)

    本文詳細(xì)講解了C#多線程中的線程完成數(shù),文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-02-02

最新評(píng)論