Deep Zoom Picture of Grant's Web Data
This project is woefully out of date and the Silverlight version it was developed for is no longer supported. Don't expect the below to work as-is.
Details
For the past two days I've been playing with Microsoft's Silverlight. It's a really cool technology. I'm most impressed with their Deep Zoom development. I decided I wanted to be able to automatically generate Deep Zoom images without using the Deep Zoom Composer. I've created a tool which:
- Reads a text file.
- Generates images representing the text.
- Uses SparseImageTool.exe in the Deep Zoom Composer package to create the Deep Zoom image.
By combining the generated files with a Silverlight application developed in Visual Studio 2008, I was able to generate this. The pictured text is all the data files that are viewable to any user in the wiki system for this website.
Code
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; using System.Drawing.Imaging; using System.Drawing.Text; using System.Drawing.Drawing2D; using System.IO; using System.Xml.Linq; using System.Diagnostics; namespace TextToImage { class Program { Font font = new Font(FontFamily.GenericMonospace, 8f); string toolPath = Path.Combine(Environment.GetFolderPath( Environment.SpecialFolder.ProgramFiles), "Microsoft\\Deep Zoom Composer\\SparseImageTool.exe"); int width = 530; int height = 525; const string readPath = @"c:\"; const string writePath = @"c:\pages\pix\"; const string name = @"web_70"; const string readExt = @".txt"; const string writeExt = @".JPG"; const string dzPath = writePath + @"dz\"; const string sceneGraphFile = dzPath + "SparseImageSceneGraph.xml"; public Program() { Console.WriteLine("TextToImage: " + readPath + name + readExt); StreamReader sr = new StreamReader(readPath + name + readExt); int picNum = 0; int lineCountNum = 0; while (!sr.EndOfStream) { Console.WriteLine("On line: " + lineCountNum); string fileLines = ""; for (int i = 0; i < 42 && (!sr.EndOfStream); i++) { lineCountNum++; fileLines += (sr.ReadLine() + "\n"); } Bitmap objBitmap = new Bitmap(width, height); Random r = new Random(); Graphics objGraphics = Graphics.FromImage(objBitmap); objGraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, width, height); objGraphics.DrawString(fileLines, font, new SolidBrush(Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255))), new Rectangle(5, 0, width, height), new StringFormat()); objBitmap.Save(writePath + name + picNum + writeExt, ImageFormat.Jpeg); objGraphics.Dispose(); picNum++; } float sqrRt = (float)Math.Ceiling(Math.Sqrt((float)(picNum + 1))); float sizeRatio = 1f / sqrRt; XElement root = new XElement("SceneGraph", new XAttribute("Version", 1)); root.Add(new XElement("AspectRatio", 1)); float zOrder = 0; float col = 0; float row = 0; foreach (FileInfo file in new DirectoryInfo(writePath).GetFiles("*.JPG")) { root.Add(new XElement("SceneNode", new XElement("FileName", file.FullName), new XElement("x", row), new XElement("y", col), new XElement("Width", sizeRatio), new XElement("Height", sizeRatio), new XElement("ZOrder", zOrder++))); row += sizeRatio; if (zOrder % sqrRt == 0) { row = 0; col += sizeRatio; } } root.Save(sceneGraphFile); string args = string.Format("CreateCollection \"{0}\" \"{1}\"", sceneGraphFile, dzPath + "dzc_output" + ".xml"); Process batch = new Process(); batch.StartInfo.FileName = toolPath; batch.StartInfo.Arguments = args; batch.StartInfo.CreateNoWindow = false; batch.StartInfo.UseShellExecute = true; batch.StartInfo.WindowStyle = ProcessWindowStyle.Normal; batch.EnableRaisingEvents = true; batch.Start(); Console.WriteLine("Done!"); } static void Main(string[] args) { new Program(); } } }