ASP.NET中製作圖形

來源:互聯網
上載者:User
asp.net|圖形 這個程式經過修改 現在作計數器的話 只能做黑白的 計數器,誰有辦法 能夠做出 複雜的 圖形計數器?

<% @Page Language="C#" %>

<% @Import Namespace="System.Drawing" %>

<% @Import Namespace="System.IO" %>

<% @Import Namespace="System.Drawing.Imaging" %>

<%

Response.Expires = 0;

Bitmap newBitmap = null;

Graphics g = null ;

string str2Render = Request.QueryString.Get("HitCount");

if (null == str2Render) str2Render = "12345";

string strFont = Request.QueryString.Get("HitFontName");

if (null == strFont) strFont = "楷體_GB2312";

int nFontSize = 12;

try

{

nFontSize = Request.QueryString.Get("HitFontSize").ToInt32();

}

catch

{

// do nothing, just ignore

}


string strBackgroundColorname = Request.QueryString.Get("HitBackgroundColor");

Color clrBackground = Color.White;

try

{

if (null != strBackgroundColorname)

clrBackground = ColorTranslator.FromHTML(strBackgroundColorname);

}

catch

{

}


string strFontColorName = Request.QueryString.Get("HitFontColor");

Color clrFont = Color.Black;

try

{

// Format in the URL: %23xxXXxx

if (null != strFontColorName)

clrFont = ColorTranslator.FromHTML(strFontColorName);

}

catch

{

}


try

{

Font fontCounter = new Font(strFont, nFontSize);

newBitmap = new Bitmap(1,1,PixelFormat.Format32bppARGB);

g = Graphics.FromImage(newBitmap);

SizeF stringSize = g.MeasureString(str2Render, fontCounter);

int nWidth = (int)stringSize.Width;

int nHeight = (int)stringSize.Height;

g.Dispose();

newBitmap.Dispose();

newBitmap = new Bitmap(nWidth,nHeight,PixelFormat.Format32bppARGB);

g = Graphics.FromImage(newBitmap);

g.FillRectangle(new SolidBrush(clrBackground), new Rectangle(0,0,nWidth,nHeight));

g.DrawString(str2Render, fontCounter, new SolidBrush(clrFont), 0, 0);

MemoryStream tempStream = new MemoryStream();

newBitmap.Save(tempStream,ImageFormat.GIF);

Response.ClearContent();

Response.ContentType = "image/GIF";

Response.BinaryWrite(tempStream.ToArray());

Response.End();

}

catch (Exception e)

{

Response.Write(e.ToString());

}

finally

{

if (null != g) g.Dispose();

if (null != newBitmap) newBitmap.Dispose();

}

%>


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.