Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- namespace PicToHtml
- {
- class Program
- {
- static void Main(string[] args)
- {
- Create("mitsudomoe.jpeg");
- Console.ReadKey();
- }
- private static void Create(string imgPath)
- {
- List<string> codes = new List<string>();
- Bitmap img = new Bitmap(imgPath);
- int l = img.Width;
- int h = img.Height;
- TextWriter tw = CreatePage(imgPath + ".html", imgPath);
- for (int i1 = 0; i1 < h; i1++)
- {
- for (int i2 = 0; i2 < l; i2++)
- {
- try
- {
- codes.Add(System.Drawing.ColorTranslator.ToHtml(img.GetPixel(i2, i1)));
- }
- catch (ArgumentOutOfRangeException aorex)
- {
- Console.WriteLine("{0} - {1} * {2}", aorex.Message, i1, i2);
- }
- }
- tw = AddLines(tw, codes);
- codes = new List<string>();
- }
- tw.Close();
- }
- private static TextWriter AddLines(TextWriter tw, List<string> pixels)
- {
- tw.Write("<tr>");
- foreach(string s in pixels)
- {
- tw.Write("<th style=\"background-color:" + s +"\"/>");
- }
- tw.Write("</tr>");
- return tw;
- }
- private static TextWriter CreatePage(string filename, string name)
- {
- string html = @"<html>
- <head>
- <style>
- .pixel th
- {
- width:1;
- height:1;
- }
- </style>
- <title>" + name + @"</title>
- </head>
- <body>";
- html += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"pixel\" >";
- html += "<caption>" + name + "</caption>";
- TextWriter tw = new StreamWriter(filename);
- tw.Write(html);
- return tw;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement