自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

詳細VB.NET代碼之圖像轉(zhuǎn)成HTML文件

開發(fā) 后端
這里就圖像轉(zhuǎn)成HTML文件案例做出詳細VB.NET代碼,想知道是怎么實現(xiàn)的嗎?文章有詳細的代碼和解釋,看了一定會給你啟發(fā)的。

VB.NET還是比較常用的,于是我研究了一下VB.NET,在這里拿出來和大家分享一下,希望對大家有用。在vb.net中寫出了相同實現(xiàn)功能的VB.NET代碼
功能實現(xiàn)主要是應用到system.drawing.bitmap,和其方法getpixel()

主要VB.NET代碼 如下:

  1. Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  
  2. Dim bit As System.Drawing.Bitmap  
  3. bitbit = bit.FromFile("c:\aowindme.bmp") '讀取一個圖像文件  
  4. Dim w, h As Integer  
  5. w = bit.Width - 1 '取得圖像每行的像素量  
  6. h = bit.Height - 1 '取得圖像的行數(shù)  
  7. Dim pixel As System.Drawing.Color(,) '定義一個類型為系統(tǒng)色彩型的二維數(shù)組,來存放圖片的所有像系的色彩信息  
  8. pixel = New System.Drawing.Color(w, h) {} '根據(jù)圖像的像系每行數(shù)量和行量來重新定義數(shù)組下標  
  9. Dim i, j  
  10. '利用循環(huán)把圖像所有像素的色彩信息對應存入數(shù)組  
  11. For i = 0 To h  
  12. For j = 0 To w  
  13. pixel(j, i) = bit.GetPixel(j, i)  
  14. Next  
  15. Next  
  16. Dim content As String '定義一個字符串來存放要寫入html的內(nèi)容  
  17. content = toweb(w, h, pixel) '生成寫入html的內(nèi)容  
  18. Dim y As Boolean '定義一個邏輯變量來判斷是否寫入成功  
  19. y = SaveTextFile("c:\999.htm", content) '寫入html文件  
  20. If y Then MsgBox("ok!")  
  21. End Sub  
  22. '得到一個RGB信息的相應WEB代碼  
  23. Private Function GetWEBColorinfo()Function GetWEBColorinfo(ByVal x As Color) As String  
  24. Dim r, g, b As String  
  25. r = Hex(CInt(x.R)) '取得一個像素色彩信息中的R信息,轉(zhuǎn)成16進制后存成字符串型  
  26. g = Hex(CInt(x.G)) '取得一個像素色彩信息中的R信息,轉(zhuǎn)成16進制后存成字符串型  
  27. b = Hex(CInt(x.B)) '取得一個像素色彩信息中的R信息,轉(zhuǎn)成16進制后存成字符串型  
  28. '如果不足兩位的在前面加0,因為WEB色彩表示應為#+R(兩位16進制)+G(兩位16進制)+B(兩位16進制)  
  29. If r.Length = 1 Then r = "0" & r  
  30. If g.Length = 1 Then g = "0" & g  
  31. If b.Length = 1 Then b = "0" & b  
  32. Return "#" & r & g & b  
  33. End Function  
  34. '生成要寫處html文件的字符串,即html文件的內(nèi)容  
  35. Private Function toweb()Function toweb(ByVal w As Integer, ByVal h As Integer, ByVal pixel As Color(,)) As String  
  36. Dim html As String  
  37. html = "<html><head><title>傲風圖像網(wǎng)頁生成</title></head><body bgcolor='#000000'><center>" & vbCrLf  
  38. Dim i, j  
  39. For i = 0 To h  
  40. For j = 0 To w  
  41. htmlhtml = html & "<font color='" & GetWEBColorinfo(pixel(j, i)) & "'>" & Int(Rnd(10) * 10) & Int(Rnd(10) * 10) & "</font>"  
  42. Next  
  43. htmlhtml = html & "<br>" & vbCrLf  
  44. Next  
  45. htmlhtml = html & "</center></body></html>"  
  46. Return html  
  47. End Function  
  48. '寫入文件函數(shù)  
  49. Private Function SaveTextFile()Function SaveTextFile(ByVal FilePath As String, ByVal FileContent As String) As Boolean  
  50. Dim sw As System.IO.StreamWriter  
  51. Try  
  52. sw = New System.IO.StreamWriter(FilePath, False)  
  53. sw.Write(FileContent)  
  54. Return True  
  55. Catch e As Exception  
  56. Return False  
  57. Finally  
  58. If Not sw Is Nothing Then sw.Close()  
  59. End Try  
  60. End Function 

以上就是將圖像轉(zhuǎn)成HTML文件,VB.NET代碼。

【編輯推薦】

  1. VB.NET編寫托盤程序經(jīng)驗雜談
  2. 手把手指導VB.NET Socket編程
  3. 快速了解VB.NET可選參數(shù)
  4. 詳細介紹VB.NET MyClass
  5. 自己動手用代碼實現(xiàn)VB.NET ListView加載數(shù)據(jù)
責任編輯:田樹 來源: 樂博網(wǎng)
相關(guān)推薦

2009-10-28 09:55:29

VB.NET MyCl

2009-10-12 15:41:09

VB.NET動態(tài)代碼

2010-01-20 13:42:10

VB.NET訪問INIGetPrivateP

2009-10-12 13:54:22

VB.NET Data

2009-10-12 15:02:51

VB.NET動態(tài)控件

2009-10-13 17:03:55

VB.NET面向?qū)ο?/a>

2009-11-02 15:45:03

VB.NET IEnu

2010-01-07 15:18:10

VB.NET常量

2010-01-21 16:45:00

VB.NET繼承規(guī)則

2010-01-22 14:19:38

VB.NET調(diào)用jar

2009-10-10 16:44:52

VB.NET開發(fā)控件

2009-11-10 12:42:47

VB.NET Prin

2010-01-12 11:37:34

VB.NET讀取圖像

2009-10-12 12:54:58

VB.NET聲明API

2009-10-15 15:04:42

VB.NET PadL

2009-10-13 17:16:40

VB.NET Web服

2009-11-02 09:45:23

VB.NET文件系統(tǒng)對

2010-01-11 11:37:08

VB.NET操作CSV

2010-01-11 11:02:27

VB.NET調(diào)用存儲過

2009-10-12 16:56:36

VB.NET常量VB.NET枚舉
點贊
收藏

51CTO技術(shù)棧公眾號