Sunday, 4 January 2009


Deep Zoom Publisher is currently getting 'upgraded' to use DeepZoomTools.dll instead of the rather clumsy "old way":
// the old way
System.Diagnostics.Process p = new Process();
p.StartInfo.FileName =
@"C:\Program Files\Microsoft Corporation\Deep Zoom Composer\sparseimagetool.exe";
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.Arguments = String.Format(
@"CreateCollection ""{0}"" ""{1}"" ",
filename, sdiname);

It works a lot better, however I was initially stumped by an error message from the Microsoft.DeepZoomTools.CollectionCreator.Create() method:
Invalid character in the given encoding. Line 1, position 1.
at System.Xml.XmlTextReaderImpl.Throw(Exception e) ...
at System.Xml.XmlTextReaderImpl.InvalidCharRecovery(Int32& bytesCount, Int32& charsCount)
at System.Xml.XmlTextReaderImpl.GetChars(Int32 maxCharsCount)
at System.Xml.XmlTextReaderImpl.Read() ...
at Microsoft.DeepZoomTools.CollectionCreator.Create(ICollection`1 images, String destination)

My initial attempt at the code was as follows:
var cc = new Microsoft.DeepZoomTools.CollectionCreator();
var imgs = new List();
var sdiname = proj.GetSdiFilename(); // custom
foreach (var f in proj.ImageList)
imgs.Add(new Image(f.File));
cc.Create(imgs, sdiname);
but the error is thrown on the cc.Create line.

Turns out to be a case of RTFM... the Expression blog specifically says
one thing that confused me was what CollectionCreator expected as its “image path”. It isn’t a string of paths to raw JPG, PNG, etc. files. It is actually a path to the Deep Zoom Image created via ImageCreator/SparseImageCreator. SparseImageCreator does take in a list of paths to the source image, so passing in a list of image files will work for generating sparse images (aka Compositions)
Bryant also had it figured out in his example... although it seems to me like the API is a little inconsistent (as the quote says). It is a preview release, so I expect this API will change soon enough...

This code works:
var cc = new Microsoft.DeepZoomTools.CollectionCreator();
var ic = new ImageCreator();
var imgs = new List();
var sdiname = proj.GetSdiFilename(); // custom
foreach (var f in proj.ImageList)
string fn = Path.GetDirectoryName(sdiname)
+ @"\" +
GetFileNameWithoutExtension(f.File) + ".xml";
ic.Create(f.File, fn);
imgs.Add(new Image(fn));
cc.Create(imgs, sdiname);

More Deep Zoom Publisher to come...

OT: of course before DeepZoomTools.dll there was Berend's CodeProject article...

1 comment:

  1. Thanks you for posting this code sample which demonstrates using DeepZoomTool.dll versus SpareImageTool.exe If has been useful, But I have had difficulty tracing the step with the proj.GetSdiFilename and proj.ImageList. It is appreciated if you could share futher details about your solution.