by Dario B. (2 Submissions)
Category: Graphics
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Mon 29th May 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)
This snippet converts a JPG or PNG image into a pure html file. The resulting html image looks exactly as the original one. It's possible to
API Declarations
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Drawing2D
'Parameters:
' imageFile: jpg or png image to convert
' htmlFile: output html file containing the converted image
' [optional] zoomFactor: ex. 2 doubles then original dimentions
' Usage example: imageToHtml("c:\logo.png", "C:\out.htm", 0.4)
Sub imageToHtml(ByVal imageFile As String, ByVal htmlFile As String, Optional ByVal zoomFactor As Double = 1)
Dim img As Bitmap = Image.FromFile(imageFile)
Dim SW As StreamWriter = New StreamWriter(htmlFile, False)
SW.WriteLine("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'><html><head><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'></head><body>")
SW.WriteLine("<table width='" & (CInt((img.Width * zoomFactor))).ToString & "' height='" & (CInt((img.Height * zoomFactor))).ToString & "' border='0' cellpadding='0' cellspacing='0'>")
For y As Double = 0 To img.Height - 1 Step 1 / zoomFactor
SW.WriteLine("<tr>")
For x As Double = 0 To img.Width - 1 Step 1 / zoomFactor
SW.WriteLine("<td bgcolor='#" & img.GetPixel(x, y).Name.Substring(2) & "'></td>")
Next
SW.WriteLine("</tr>")
Next
SW.WriteLine("</table></body></html>")
SW.Close()
SW = Nothing
End Sub
No comments have been posted about This snippet converts a JPG or PNG image into a pure html file. The resulting html image looks exac. Why not be the first to post a comment about This snippet converts a JPG or PNG image into a pure html file. The resulting html image looks exac.