本文實(shí)例為大家分享了C#實(shí)現(xiàn)網(wǎng)頁(yè)畫圖的具體代碼,供大家參考,具體內(nèi)容如下
創(chuàng)新互聯(lián)主要從事網(wǎng)頁(yè)設(shè)計(jì)、PC網(wǎng)站建設(shè)(電腦版網(wǎng)站建設(shè))、wap網(wǎng)站建設(shè)(手機(jī)版網(wǎng)站建設(shè))、響應(yīng)式網(wǎng)站開發(fā)、程序開發(fā)、網(wǎng)站優(yōu)化、微網(wǎng)站、成都微信小程序等,憑借多年來(lái)在互聯(lián)網(wǎng)的打拼,我們?cè)诨ヂ?lián)網(wǎng)網(wǎng)站建設(shè)行業(yè)積累了豐富的成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、網(wǎng)站設(shè)計(jì)、網(wǎng)絡(luò)營(yíng)銷經(jīng)驗(yàn),集策劃、開發(fā)、設(shè)計(jì)、營(yíng)銷、管理等多方位專業(yè)化運(yùn)作于一體。代碼貼著保存下
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 h2 = (int)(0.1 * h); int h3 = (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(h2,h3), 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)); } }
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)頁(yè)題目:C#實(shí)現(xiàn)網(wǎng)頁(yè)畫圖功能-創(chuàng)新互聯(lián)
分享網(wǎng)址:http://bm7419.com/article10/ipgdo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)、網(wǎng)頁(yè)設(shè)計(jì)公司、云服務(wù)器、網(wǎng)站維護(hù)、小程序開發(fā)、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容