11突然在网上看见有人介绍个有意思的软件可以将图象转化为HTML来呈现,觉得很有意思
结果找半天没找到下载地址,于是决定自己动手写写看
'**********************
'APP name:Img2Html
'AUTHOR:wgscd(自由奔腾)
'date:2005-8-26
'E-Mail:wgscd@126.com
'QQ:153964481
'**********************
Dim StrFont As String = "王"'wgscd
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim bm1 As Bitmap = PictureBox1.Image
Dim bm As New Bitmap(bm1, bm1.Width / Me.ComboBox2.Text, bm1.Height / Me.ComboBox2.Text)
Dim i As Integer
Dim Img As Bitmap
Dim Sb As System.Text.StringBuilder
Dim Sw As IO.StreamWriter
Try
' Img = Bitmap.FromFile(StrImg)
Img = bm
Sb = New System.Text.StringBuilder
Sb.Append("<html><head><title>Img2Html By wgscd(自由奔腾)</title></head><body style=""font-size: " & ComboBox1.Text & "pt"" bgcolor=""#" & int2Hex(Label4.BackColor.R) & int2Hex(Label4.BackColor.G) & int2Hex(Label4.BackColor.B) & """><meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"">" & vbCrLf)
' Dim str as String="<pre style="BACKGROUND-COLOR: rgb(0,0,0)"><font size="-1">"
Me.ProgressBar1.Maximum = bm.Height
For h As Integer = 0 To Img.Height - 1
For w As Integer = 0 To Img.Width - 1
Dim c As Color = Img.GetPixel(w, h)
Sb.Append("<font color=#" & int2Hex(c.R) & int2Hex(c.G) & int2Hex(c.B) & ">" & TextBox1.Text & "</font>")
Next
Sb.Append("<br>" & vbCrLf)
i += 1
Me.ProgressBar1.Value = i
Next
Sb.Append("</body></html>")
Sw = New IO.StreamWriter("1.htm", False, System.Text.Encoding.GetEncoding("Gb2312"))
Sw.Write(Sb.ToString)
Catch ex As Exception
MsgBox("看起来不是图片。。")
Finally
Img.Dispose()
If Not Sw Is Nothing Then
Sw.Close()
End If
Dim p As New Process
p.Start("1.htm")
End Try
End Sub
Function int2Hex(ByVal Int As Int32) As String
Return System.Convert.ToString(Int, 16)
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.PictureBox1.AllowDrop = True
End Sub
Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
Dim cdg As New ColorDialog
If cdg.ShowDialog = DialogResult.OK Then
Label4.BackColor = cdg.Color
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "设置" Then
Me.Height = 566
Button1.Text = "-"
Else
Me.Height = 400
Button1.Text = "设置"
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
OpenImg()
End Sub
Sub OpenImg()
Dim ofd As New OpenFileDialog
ofd.Filter = "图片文件(*.jpg,*.gif,*.pnp,*.bmp)|*.jpg;*.gif:*.pnp;*.bmp"
If ofd.ShowDialog = DialogResult.OK Then
Me.PictureBox1.Image = Image.FromFile(ofd.FileName)
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
TextBox1.MaxLength = 1
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
End Sub
Private Sub PictureBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.DoubleClick
OpenImg()
End Sub
Private Sub PictureBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragEnter
If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
e.Effect = DragDropEffects.All
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub PictureBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragDrop
Dim file() As String = e.Data.GetData(DataFormats.FileDrop)
For i As Integer = 0 To file.Length
If file(i).ToLower Like "*.jpg" Or file(i).ToLower Like "*.gif" Or file(i).ToLower Like "*.bmp" Or file(i).ToLower Like "*.pnp" Then
Me.PictureBox1.Image = Image.FromFile(file(i))
Else : Return
End If
Next
' Me.PictureBox1.Image = Image.FromFile(e.Data.GetData(DataFormats.Bitmap))
End Sub
End Class