{"id":767,"date":"2011-11-18T00:05:59","date_gmt":"2011-11-17T16:05:59","guid":{"rendered":""},"modified":"2014-03-11T22:40:49","modified_gmt":"2014-03-11T14:40:49","slug":"asp%e5%ae%9e%e7%8e%b0%e6%97%a0%e7%bb%84%e4%bb%b6%e7%94%9f%e6%88%90gif%e6%a0%bc%e5%bc%8f%e9%aa%8c%e8%af%81%e7%a0%81","status":"publish","type":"post","link":"http:\/\/www.xiaoyebailong.com\/index.php\/2011\/11\/18\/767.htm","title":{"rendered":"ASP\u5b9e\u73b0\u65e0\u7ec4\u4ef6\u751f\u6210GIF\u683c\u5f0f\u9a8c\u8bc1\u7801"},"content":{"rendered":"<p>ASP\u5b9e\u73b0\u65e0\u7ec4\u4ef6\u751f\u6210GIF\u683c\u5f0f\u9a8c\u8bc1\u7801\uff0c\u9700\u8981asp\u9a8c\u8bc1\u7801\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b\u3002<\/p>\n<p>&lt;% <br \/>\nOption Explicit &#8216; \u663e\u793a\u58f0\u660e <br \/>\nClass Com_GifCode_Class <br \/>\nPublic Noisy, Count, Width, Height, Angle, Offset, Border <br \/>\nPrivate Graph(), Margin(3) <br \/>\nPrivate Sub Class_Initialize() <br \/>\nRandomize <br \/>\nNoisy = 16 &#8216; \u5e72\u6270\u70b9\u51fa\u73b0\u7684\u6982\u7387 <br \/>\nCount = 4 &#8216; \u5b57\u7b26\u6570\u91cf <br \/>\nWidth = 80 &#8216; \u56fe\u7247\u5bbd\u5ea6 <br \/>\nHeight = 20 &#8216; \u56fe\u7247\u9ad8\u5ea6 <br \/>\nAngle = 2 &#8216; \u89d2\u5ea6\u968f\u673a\u53d8\u5316\u91cf <br \/>\nOffset = 20 &#8216; \u504f\u79fb\u968f\u673a\u53d8\u5316\u91cf <br \/>\nBorder = 1 &#8216; \u8fb9\u6846\u5927\u5c0f <br \/>\nEnd Sub <br \/>\nPublic Function Create() <br \/>\nConst cCharSet = &quot;123456789&quot; <br \/>\nDim i, x, y <br \/>\nDim vValidCode : vValidCode = &quot;&quot; <br \/>\nDim vIndex <br \/>\nReDim Graph(Width-1, Height-1) <br \/>\nFor i = 0 To Count &#8211; 1 <br \/>\nvIndex = Int(Rnd * Len(cCharSet)) <br \/>\nvValidCode = vValidCode + Mid(cCharSet, vIndex+1 , 1) <br \/>\nSetDraw vIndex, i <br \/>\nNext <br \/>\nCreate = vValidCode <br \/>\nEnd Function <br \/>\nSub SetDot(pX, pY) <br \/>\nIf pX * (Width-pX-1) &gt;= 0 And pY * (Height-pY-1) &gt;= 0 Then <br \/>\nGraph(pX, pY) = 1 <br \/>\nEnd If <br \/>\nEnd Sub <br \/>\nPublic Sub SetDraw(pIndex, pNumber) <br \/>\n&#8216; \u5b57\u7b26\u6570\u636e <br \/>\nDim DotData(8) <br \/>\nDotData(0) = Array(30, 15, 50, 1, 50, 100) <br \/>\nDotData(1) = Array(1 ,34 ,30 ,1 ,71, 1, 100, 34, 1, 100, 93, 100, 100, 86) <br \/>\nDotData(2) = Array(1, 1, 100, 1, 42, 42, 100, 70, 50, 100, 1, 70) <br \/>\nDotData(3) = Array(100, 73, 6, 73, 75, 6, 75, 100) <br \/>\nDotData(4) = Array(100, 1, 1, 1, 1, 50, 50, 35, 100, 55, 100, 80, 50, 100, 1, 95) <br \/>\nDotData(5) = Array(100, 20, 70, 1, 20, 1, 1, 30, 1, 80, 30, 100, 70, 100, 100, 80, 100, 60, 70, 50, 30, 50, 1, 60) <br \/>\nDotData(6) = Array(6, 26, 6, 6, 100, 6, 53, 100) <br \/>\nDotData(7) = Array(100, 30, 100, 20, 70, 1, 30, 1, 1, 20, 1, 30, 100, 70, 100, 80, 70, 100, 30, 100, 1, 80, 1, 70, 100, 30) <br \/>\nDotData(8) = Array(1, 80, 30, 100, 80, 100, 100, 70, 100, 20, 70, 1, 30, 1, 1, 20, 1, 40, 30, 50, 70, 50, 100, 40) <br \/>\nDim vExtent : vExtent = Width \/ Count <br \/>\nMargin(0) = Border + vExtent * (Rnd * Offset) \/ 100 + Margin(1) <br \/>\nMargin(1) = vExtent * (pNumber + 1) &#8211; Border &#8211; vExtent * (Rnd * Offset) \/ 100 <br \/>\nMargin(2) = Border + Height * (Rnd * Offset) \/ 100 <br \/>\nMargin(3) = Height &#8211; Border &#8211; Height * (Rnd * Offset) \/ 100 <br \/>\nDim vStartX, vEndX, vStartY, vEndY <br \/>\nDim vWidth, vHeight, vDX, vDY, vDeltaT <br \/>\nDim vAngle, vLength <br \/>\nvWidth = Int(Margin(1) &#8211; Margin(0)) <br \/>\nvHeight = Int(Margin(3) &#8211; Margin(2)) <br \/>\n&#8216; \u8d77\u59cb\u5750\u6807 <br \/>\nvStartX = Int((DotData(pIndex)(0)-1) * vWidth \/ 100) <br \/>\nvStartY = Int((DotData(pIndex)(1)-1) * vHeight \/ 100) <br \/>\nDim i, j <br \/>\nFor i = 1 To UBound(DotData(pIndex), 1)\/2 <br \/>\nIf DotData(pIndex)(2*i-2) &lt;&gt; 0 And DotData(pIndex)(2*i) &lt;&gt; 0 Then <br \/>\n&#8216; \u7ec8\u70b9\u5750\u6807 <br \/>\nvEndX = (DotData(pIndex)(2*i)-1) * vWidth \/ 100 <br \/>\nvEndY = (DotData(pIndex)(2*i+1)-1) * vHeight \/ 100 <br \/>\n&#8216; \u6a2a\u5411\u5dee\u8ddd <br \/>\nvDX = vEndX &#8211; vStartX <br \/>\n&#8216; \u7eb5\u5411\u5dee\u8ddd <br \/>\nvDY = vEndY &#8211; vStartY <br \/>\n&#8216; \u503e\u659c\u89d2\u5ea6 <br \/>\nIf vDX = 0 Then <br \/>\nvAngle = Sgn(vDY) * 3.14\/2 <br \/>\nElse <br \/>\nvAngle = Atn(vDY \/ vDX) <br \/>\nEnd If <br \/>\n&#8216; \u4e24\u5750\u6807\u8ddd\u79bb <br \/>\nIf Sin(vAngle) = 0 Then <br \/>\nvLength = vDX <br \/>\nElse <br \/>\nvLength = vDY \/ Sin(vAngle) <br \/>\nEnd If <br \/>\n&#8216; \u968f\u673a\u8f6c\u52a8\u89d2\u5ea6 <br \/>\nvAngle = vAngle + (Rnd &#8211; 0.5) * 2 * Angle * 3.14 * 2 \/ 100 <br \/>\nvDX = Int(Cos(vAngle) * vLength) <br \/>\nvDY = Int(Sin(vAngle) * vLength) <br \/>\nIf Abs(vDX) &gt; Abs(vDY) Then vDeltaT = Abs(vDX) Else vDeltaT = Abs(vDY) <br \/>\nFor j = 1 To vDeltaT <br \/>\nSetDot Margin(0) + vStartX + j * vDX \/ vDeltaT, Margin(2) + vStartY + j * vDY \/ vDeltaT <br \/>\nNext <br \/>\nvStartX = vStartX + vDX <br \/>\nvStartY = vStartY + vDY <br \/>\nEnd If <br \/>\nNext <br \/>\nEnd Sub <br \/>\nPublic Sub Output() <br \/>\nResponse.Expires = -9999 <br \/>\nResponse.AddHeader &quot;pragma&quot;, &quot;no-cache&quot; <br \/>\nResponse.AddHeader &quot;cache-ctrol&quot;, &quot;no-cache&quot; <br \/>\nResponse.ContentType = &quot;image\/gif&quot; <br \/>\n&#8216; \u6587\u4ef6\u7c7b\u578b <br \/>\nResponse.BinaryWrite ChrB(Asc(&quot;G&quot;)) &amp; ChrB(Asc(&quot;I&quot;)) &amp; ChrB(Asc(&quot;F&quot;)) <br \/>\n&#8216; \u7248\u672c\u4fe1\u606f <br \/>\nResponse.BinaryWrite ChrB(Asc(&quot;8&quot;)) &amp; ChrB(Asc(&quot;9&quot;)) &amp; ChrB(Asc(&quot;a&quot;)) <br \/>\n&#8216; \u903b\u8f91\u5c4f\u5e55\u5bbd\u5ea6 <br \/>\nResponse.BinaryWrite ChrB(Width Mod 256) &amp; ChrB((Width \\ 256) Mod 256) <br \/>\n&#8216; \u903b\u8f91\u5c4f\u5e55\u9ad8\u5ea6 <br \/>\nResponse.BinaryWrite ChrB(Height Mod 256) &amp; ChrB((Height \\ 256) Mod 256) <br \/>\nResponse.BinaryWrite ChrB(128) &amp; ChrB(0) &amp; ChrB(0) <br \/>\n&#8216; \u5168\u5c40\u989c\u8272\u5217\u8868 <br \/>\nResponse.BinaryWrite ChrB(255) &amp; ChrB(255) &amp; ChrB(255) <br \/>\nResponse.BinaryWrite ChrB(0) &amp; ChrB(85) &amp; ChrB(255) <br \/>\n&#8216; \u56fe\u8c61\u6807\u8bc6\u7b26 <br \/>\nResponse.BinaryWrite ChrB(Asc(&quot;,&quot;)) <br \/>\nResponse.BinaryWrite ChrB(0) &amp; ChrB(0) &amp; ChrB(0) &amp; ChrB(0) <br \/>\n&#8216; \u56fe\u8c61\u5bbd\u5ea6 <br \/>\nResponse.BinaryWrite ChrB(Width Mod 256) &amp; ChrB((Width \\ 256) Mod 256) <br \/>\n&#8216; \u56fe\u8c61\u9ad8\u5ea6 <br \/>\nResponse.BinaryWrite ChrB(Height Mod 256) &amp; ChrB((Height \\ 256) Mod 256) <br \/>\nResponse.BinaryWrite ChrB(0) &amp; ChrB(7) &amp; ChrB(255) <br \/>\nDim x, y, i : i = 0 <br \/>\nFor y = 0 To Height &#8211; 1 <br \/>\nFor x = 0 To Width &#8211; 1 <br \/>\nIf Rnd &lt; Noisy \/ 100 Then <br \/>\nResponse.BinaryWrite ChrB(1-Graph(x, y)) <br \/>\nElse <br \/>\nIf x * (x-Width) = 0 Or y * (y-Height) = 0 Then <br \/>\nResponse.BinaryWrite ChrB(Graph(x, y)) <br \/>\nElse <br \/>\nIf Graph(x-1, y) = 1 Or Graph(x, y) Or Graph(x, y-1) = 1 Then <br \/>\nResponse.BinaryWrite ChrB(1) <br \/>\nElse <br \/>\nResponse.BinaryWrite ChrB(0) <br \/>\nEnd If <br \/>\nEnd If <br \/>\nEnd If <br \/>\nIf (y * Width + x + 1) Mod 126 = 0 Then <br \/>\nResponse.BinaryWrite ChrB(128) <br \/>\ni = i + 1 <br \/>\nEnd If <br \/>\nIf (y * Width + x + i + 1) Mod 255 = 0 Then <br \/>\nIf (Width*Height &#8211; y * Width &#8211; x &#8211; 1) &gt; 255 Then <br \/>\nResponse.BinaryWrite ChrB(255) <br \/>\nElse <br \/>\nResponse.BinaryWrite ChrB(Width * Height Mod 255) <br \/>\nEnd If <br \/>\nEnd If <br \/>\nNext <br \/>\nNext <br \/>\nResponse.BinaryWrite ChrB(128) &amp; ChrB(0) &amp; ChrB(129) &amp; ChrB(0) &amp; ChrB(59) <br \/>\nEnd Sub <br \/>\nEnd Class <br \/>\nDim mCode <br \/>\nSet mCode = New Com_GifCode_Class <br \/>\nSession(&quot;GetCode&quot;) = mCode.Create() <br \/>\nmCode.Output() <br \/>\nSet mCode = Nothing <br \/>\n%&gt; <br \/>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ASP\u5b9e\u73b0\u65e0\u7ec4\u4ef6\u751f\u6210GIF\u683c\u5f0f\u9a8c\u8bc1\u7801\uff0c\u9700\u8981asp\u9a8c\u8bc1\u7801\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b\u3002 &lt;% Option Explicit &#8216; \u663e\u793a\u58f0\u660e Class Com_GifCode_Class Public Noisy, Count, Wid&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"topic":[],"class_list":["post-767","post","type-post","status-publish","format-standard","hentry","category-technology"],"_links":{"self":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/767","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/comments?post=767"}],"version-history":[{"count":1,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/767\/revisions"}],"predecessor-version":[{"id":66634,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/767\/revisions\/66634"}],"wp:attachment":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/media?parent=767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/categories?post=767"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/tags?post=767"},{"taxonomy":"topic","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/topic?post=767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}