程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> ASP編程 >> ASP技巧 >> 用asp程序編寫一個bmp圖片格式的五星紅旗

用asp程序編寫一個bmp圖片格式的五星紅旗

編輯:ASP技巧

今天看到一個用ASP程序編寫一個bmp圖片格式的五星紅旗,像手繪的一樣,很好,把它轉過來和大家分享

vIEw source print? 001 <% 002 Option Explicit 003 Class FiveStarredFlag 004     PRivate Width 005     Private Height 006     Private Filler 007     Private SizeImage 008     Private FileSize 009     Private BitMap() 010   011     Private Sub Class_Initialize 012         Height = 200 013         Width = 300 014         Filler = (32 - Width Mod 32) Mod 32 015         SizeImage = (Width + Filler) * Height \ 8 016         FileSize = SizeImage + 14 + 40 + 8 017   018         ReDim BitMap(Width + Filler - 1, Height - 1) 019   020         Star Height * 0.25, Height * 0.75, Height * 0.15, 0 021         Star Width / 3, Height * 0.9, Height * 0.05, 120.9637565320735 022         Star Width * 0.4, Height * 0.8, Height * 0.05, 98.13010235415598 023         Star Width * 0.4, Height * 0.65, Height * 0.05, 74.0546040990771 024         Star Width / 3, Height * 0.55, Height * 0.05, 51.3401917459099 025     End Sub 026   027     Private Sub Class_Terminate 028         Response.ContentType = "image/bmp" 029         Response.BinaryWrite FileHeader & InfoHeader & Palette & ImageData 030     End Sub 031   032     Private Sub Star(x, y, r, a) 033         Dim pi, v, d, i, j, k, m2 034   035         pi = 3.1415926535897932 036         v = r * Sin(pi * 0.1) / Sin(pi * 0.7) 037   038         For j = -r To r 039             For i = -r To r 040                 d = Sqr(i ^ 2 + j ^ 2) 041   042                 If d < v Then 043                     BitMap(x + i, y + j) = 1 044                 ElseIf d < r Then 045                     If i = 0 Then 046                         If j > 0 Then k = 90 Else k = -90 047                     Else 048                         k = Atn(j / i) * 180 / pi 049                         If i < 0 Then k = k + 180 050                     End If 051   052                     k = k - a - 18 053                     While k < 0 054                         k = k + 360 055                     Wend 056                     While k >= 360 057                         k = k - 360 058                     Wend 059                     While k >= 72 060                         k = k - 72 061                     Wend 062                     If k > 36 Then k = 72 - k 063   064                     m2 = d ^ 2 + r ^ 2 - d * r * 2 * Cos(k * pi / 180) 065                     If (m2 + r ^ 2 - d ^ 2) / (Sqr(m2) * r * 2) > Cos(pi * 0.1) Then 066                         BitMap(x + i, y + j) = 1 067                     End If 068                 End If 069             Next 070         Next 071     End Sub 072   073     Private Function CWord(I16) 074         CWord = ChrB(I16 And &HFF) & ChrB(I16 \ 256 And &HFF) 075     End Function 076   077     Private Function CDWord(I32) 078         CDWord = ChrB(I32 And &HFF) & ChrB(I32 \ 256 And &HFF) & ChrB(I32 \ 65536 And &HFF) & ChrB(I32 \ &HFFFFFF And &HFF) 079     End Function 080   081     Private Property Get FileHeader 082         Const FileType = &H4D42 083         Const Reserved1 = 0 084         Const Reserved2 = 0 085         Const OffBits = 62 086         FileHeader = CWord(FileType) & CDWord(FileSize) & CWord(Reserved1) & CWord(Reserved2) & CDWord(OffBits) 087     End Property 088   089     Private Property Get InfoHeader 090         Const InfoSize = 40 091         Const Planes = 1 092         Const BitCount = 1 093         Const Compression = 0 094         Const XPelsPerMeter = 0 095         Const YPelsPerMeter = 0 096         Const ClrUsed = 0 097         Const ClrImportant = 0 098         InfoHeader = CDWord(InfoSize) & CDWord(Width) & CDWord(Height) & CWord(Planes) & CWord(BitCount) & CDWord(Compression) & CDWord(SizeImage) & CDWord(XPelsPerMeter) & CDWord(YPelsPerMeter) & CDWord(ClrUsed) & CDWord(ClrImportant) 099     End Property 100   101     Private Property Get Palette 102         Const BackColor = &HFF0000 103         Const ForeColor = &HFFFF00 104         Palette = CDWord(BackColor) & CDWord(ForeColor) 105     End Property 106   107     Private Property Get ImageData 108         Dim i, j 109         ImageData = "" 110         For j = 0 To Height - 1 111             For i = 0 To Width + Filler - 1 Step 8 112                 ImageData = ImageData & ChrB(BitMap(i, j) * 128 or BitMap(i + 1, j) * 64 or BitMap(i + 2, j) * 32 or BitMap(i + 3, j) * 16 or BitMap(i + 4, j) * 8 or BitMap(i + 5, j) * 4 or BitMap(i + 6, j) * 2 or BitMap(i + 7, j)) 113             Next 114         Next 115     End Property 116 End Class 117   118 With New FiveStarredFlag 119 End With 120 %>
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved